Skip to content

Instantly share code, notes, and snippets.

@gipi
Last active February 1, 2016 21:49
Show Gist options
  • Save gipi/7c9c4af5e5699c9d2626 to your computer and use it in GitHub Desktop.
Save gipi/7c9c4af5e5699c9d2626 to your computer and use it in GitHub Desktop.
#machinelearning

Installing scikit-learn

# sudo apt-get install libblas-dev liblapack-dev libatlas-base-dev gfortran
$ pip install numpy
$ pip install scipy
$ pip install scikit-learn

(source)

>>> import numpy as np
>>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
>>> Y = np.array([1, 1, 1, 2, 2, 2])
>>> from sklearn.naive_bayes import GaussianNB
>>> clf = GaussianNB()
>>> clf.fit(X, Y)
GaussianNB()
>>> print(clf.predict([[-0.8, -1]]))
[1]
>>> clf_pf = GaussianNB()
>>> clf_pf.partial_fit(X, Y, np.unique(Y))
GaussianNB()
>>> print(clf_pf.predict([[-0.8, -1]]))
[1]
import sys
from class_vis import prettyPicture
from prep_terrain_data import makeTerrainData

import matplotlib.pyplot as plt
import copy
import numpy as np
import pylab as pl


features_train, labels_train, features_test, labels_test = makeTerrainData()


########################## SVM #################################
### we handle the import statement and SVC creation for you here
from sklearn.svm import SVC
clf = SVC(kernel="linear")


#### now your job is to fit the classifier
#### using the training features/labels, and to
#### make a set of predictions on the test data
clf.fit(features_train, labels_train)


#### store your predictions in a list named pred
pred = clf.predict(features_test)




from sklearn.metrics import accuracy_score
acc = accuracy_score(pred, labels_test)

def submitAccuracy():
    return acc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment