<gh_stars>0
# -*- coding: utf-8 -*-
"""TP Final - Machine Learning.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/18YTpUacvNtPKlMttEMHgF62ATCHDEDSv

# Trabalho Prático de Machine Learning - MNist

### Aluno: <NAME>
### Número: 2016006379
"""

import sklearn as sk
import pandas as pd
import numpy as np
import requests
import os
from sklearn.neighbors import NearestCentroid
from sklearn.linear_model import PassiveAggressiveClassifier    
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import Perceptron
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.ensemble import AdaBoostClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.neural_network import MLPClassifier
from sklearn.svm import SVC
import math
import collections
import random
import statistics 
import matplotlib.pyplot as plt
import pprint
import sys
from joblib import dump, load

# Puxar o arquivo da web e contornar as limitações do collab
# train_data = pd.read_csv("https://raw.githubusercontent.com/EvandroLucas/KoiTP/master/mnist_train.csv")
# test_data = pd.read_csv("https://raw.githubusercontent.com/EvandroLucas/KoiTP/master/mnist_test.csv")
train_data = pd.read_csv("mnist_train.csv")
test_data = pd.read_csv("mnist_test.csv")

num_lines = 50000
X = train_data.drop("label",1).iloc[0:num_lines,0:].to_numpy()
y = train_data["label"].iloc[0:num_lines].to_numpy()


clfs = {
    "GaussianNB" : GaussianNB(),
    "LinearSVM" : SVC(kernel="linear", C=0.025),
    "RBF_SVM" :  SVC(gamma=2, C=1),
    "MLPClassifier" : MLPClassifier(),
    "DecisionTreeClassifier" : DecisionTreeClassifier(),
    "GradientBoostingClassifier" : GradientBoostingClassifier(),
    "AdaBoostClassifier" : AdaBoostClassifier(),
    "Perceptron" : Perceptron(),
    "PassiveAggressiveClassifier" : PassiveAggressiveClassifier(),
    "NearestCentroid" : NearestCentroid(),
    "RandomForestClassifier" : RandomForestClassifier()
}


for key, clf in clfs.items():
    print("Training : " + str(key))
    clf.fit(X,y)
    dump(clf, "per/"+str(key)+".joblib") 

# -*- coding: utf-8 -*-
"""TP Final - Machine Learning.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/18YTpUacvNtPKlMttEMHgF62ATCHDEDSv

# Trabalho Prático de Machine Learning - MNist

### Aluno: <NAME>
### Número: 2016006379
"""

import sklearn as sk
import pandas as pd
import numpy as np
import requests
import os
from sklearn.neighbors import NearestCentroid
from sklearn.linear_model import PassiveAggressiveClassifier    
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import Perceptron
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.ensemble import AdaBoostClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.neural_network import MLPClassifier
from sklearn.svm import SVC
import math
import collections
import random
import statistics 
import matplotlib.pyplot as plt
import pprint
import sys
from joblib import dump, load

# Puxar o arquivo da web e contornar as limitações do collab
# train_data = pd.read_csv("https://raw.githubusercontent.com/EvandroLucas/KoiTP/master/mnist_train.csv")
# test_data = pd.read_csv("https://raw.githubusercontent.com/EvandroLucas/KoiTP/master/mnist_test.csv")
train_data = pd.read_csv("mnist_train.csv")
test_data = pd.read_csv("mnist_test.csv")

num_lines = 50000
X = train_data.drop("label",1).iloc[0:num_lines,0:].to_numpy()
y = train_data["label"].iloc[0:num_lines].to_numpy()


clfs = {
    "GaussianNB" : GaussianNB(),
    "LinearSVM" : SVC(kernel="linear", C=0.025),
    "RBF_SVM" :  SVC(gamma=2, C=1),
    "MLPClassifier" : MLPClassifier(),
    "DecisionTreeClassifier" : DecisionTreeClassifier(),
    "GradientBoostingClassifier" : GradientBoostingClassifier(),
    "AdaBoostClassifier" : AdaBoostClassifier(),
    "Perceptron" : Perceptron(),
    "PassiveAggressiveClassifier" : PassiveAggressiveClassifier(),
    "NearestCentroid" : NearestCentroid(),
    "RandomForestClassifier" : RandomForestClassifier()
}


for key, clf in clfs.items():
    print("Training : " + str(key))
    clf.fit(X,y)
    dump(clf, "per/"+str(key)+".joblib")
# -*- coding: utf-8 -*- TP Final - Machine Learning.ipynb  Automatically generated by Colaboratory.  Original file is located at     https://colab.research.google.com/drive/18YTpUacvNtPKlMttEMHgF62ATCHDEDSv  # Trabalho Prático de Machine Learning - MNist  ### Aluno: <NAME> ### Número: 2016006379 # Puxar o arquivo da web e contornar as limitações do collab # train_data = pd.read_csv("https://raw.githubusercontent.com/EvandroLucas/KoiTP/master/mnist_train.csv") # test_data = pd.read_csv("https://raw.githubusercontent.com/EvandroLucas/KoiTP/master/mnist_test.csv")