MarinaRomanova / CoreMLTwitterPredictions

completed tutorial of Core ML

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CoreMLTwitterPredictions

completed tutorial of CoreML by The App Brewery

Table of Contents

App description

A simple one page iOS app that takes user's input and queries Twitter's API to get 100 full text tweets in English. These tweets are than evaluated by the ML Model to determine whether those tweets are positive, negative or neutral. Based on the calculated total score an emoji is displayed.

Used cocopods and frameworks:

Create and Train your model

  • Create macOS Playground
import Cocoa
import CreateML

//Specify the path to the DataSet
let data = try MLDataTable(contentsOf: URL(fileURLWithPath: "/Users/User/Downloads/twitter-sanders-apple3.csv"))

//Devide the DataSet into TrainingData (80% of data) and TestingData (20%)
let(trainingData, testingData) = data.randomSplit(by: 0.8, seed: 5)

let sentimentClassifier = try MLTextClassifier(trainingData: trainingData, textColumn: "text", labelColumn: "class")


//if you wish to check the accuracy
let evaluationMetrics = sentimentClassifier.evaluation(on: testingData, textColumn: "text", labelColumn: "class")
let evaluationAccuracy = (1.0 - evaluationMetrics.classificationError) * 100

//Create MetaData for your model
let metadata = MLModelMetadata(author: "Marina", shortDescription: "A model trained to classify sentiment on Tweets", version: "1.0")

//Save the mlmodel to a file, specify the path and file's name
try sentimentClassifier.write(to: URL(fileURLWithPath: "/Users/User/Downloads/TweetSentimentClassifier.mlmodel"))

//if you wish to test manualy
try sentimentClassifier.prediction(from: "@Apple is a terrible company") // should return Negative
try sentimentClassifier.prediction(from: "I just found the best restaurant ever") // should return Positive
try sentimentClassifier.prediction(from: "I think @CocaCola ads are ok.") // should return Neutral

Get Twitter API key

About

completed tutorial of Core ML


Languages

Language:Swift 96.0%Language:Ruby 4.0%