Created
June 27, 2019 22:37
-
-
Save rafaelnovello/e8d843f3a135db436175cd505a0a9cff to your computer and use it in GitHub Desktop.
Marvin Engine Example Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Data Acquisitor | |
from marvin_python_toolbox.common.data import MarvinData | |
import pandas as pd | |
file_path = MarvinData.download_file(url="https://s3.amazonaws.com/marvin-engines-data/Iris.csv") | |
iris = pd.read_csv(file_path) | |
iris.drop('Id',axis=1,inplace=True) | |
marvin_initial_dataset = iris | |
// Training Preparator | |
from sklearn.cross_validation import train_test_split | |
train, test = train_test_split(marvin_initial_dataset, test_size = 0.3) | |
train_X = train[['SepalLengthCm','SepalWidthCm','PetalLengthCm','PetalWidthCm']] | |
train_y = train.Species | |
test_X = test[['SepalLengthCm','SepalWidthCm','PetalLengthCm','PetalWidthCm']] | |
test_y =test.Species | |
marvin_dataset = {'train_X': train_X, 'train_y': train_y, 'test_X': test_X, 'test_y': test_y} | |
// Model Traning | |
from sklearn import svm | |
clf = svm.SVC() | |
model = clf.fit(marvin_dataset['train_X'], marvin_dataset['train_y']) | |
marvin_model = model | |
// Model Evaluation | |
from sklearn.metrics import accuracy_score | |
predicted = marvin_model.predict(marvin_dataset['test_X']) | |
metric = accuracy_score(marvin_dataset['test_y'], predicted) | |
marvin_metrics = metric | |
// Prediction Preparator | |
input_message = ['12', '34', '10', '23'] | |
// Predictor | |
final_prediction = marvin_model.predict(input_message)[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment