• Aucun résultat trouvé

Machine Learning Python, R

N/A
N/A
Protected

Academic year: 2022

Partager "Machine Learning Python, R"

Copied!
6
0
0

Texte intégral

(1)

Machine Learning Python, R

Nicolas Loménie

http://www.math-info.univ-paris5.fr/~lomn/

13 avril 2018

(2)

Le sur-apprentissage

R

Cet exemple va illustrer le problème du sur-apprentissage (en R).

Algorithm 1: overfitting with R x←1:10

y←x+c(−0.5,0.5) plot(x,y)

model1<−lm(y∼x)

z <−seq(1,10,length.out=250)

lines(z,predict(model1,data.frame(x =z)),lty =1)

Ajouter le graphique avec un modèle polynomial en x d’ordre 3, puis 9. (Utilisez la fonctionpoly(x,n)) Commentez. Changer un peu les données d’entréesx←c(1:5,10:15). Commentez. Appliquez vos connaissances (TP1) pour améliorer vos graphiques à votre guise.

(3)

Machine Learning avec python

Algorithm 2: sklearn and digits

Data: from sklearn.datasets import load_digits

from sklearn.ensemble import GradientBoostingClassifier from sklearn.cross_validation import train_test_split digits=load_digits()

X =digits.data y=digits.target

/* Comment est fait cet ensemble d’apprentissage */

printdigits

Data: import matplotlib.pyplot as plt

ex=X[0].reshape(8,8); // pour visualiser le vecteur en matrice image

plt.gray() plt.matshow(ex) plt.show()

3/4

(4)

Machine Learning avec python

Algorithm 3: sklearn and digits

/* Allez chercher plus loin dans le fichier d’autres

exemples de chiffres */

Xtrain,Xtest,ytrain,ytest=train_test_split(X,y) gb=GradientBoostingClassifier(n_estimators =20) gb.fit(Xtrain,ytrain)

print(gb.estimators_[0])

/* Optionnel car nécessite graphviz (visualisation de graphes) - installation requise */

Data: from sklearn.externals.six import StringIO from sklearn.tree import export_graphviz from IPython.display import Image import pydot

tree0=gb.estimators_[0][0]) dot_data=StringIO()

export_graphviz(tree0,outfile = ”dot_data”)

(5)

Machine Learning avec python

sklearn et circles

Algorithm 4: sklearn and non-linear mapping Data: from sklearn.datasets import make_circles from sklearn.svm import LinearSVC

from sklearn.cross_validation import train_test_split from sklearn.metrics import accuracy_score

X,y =make_circles(n_samples =1000,noise =0.11,factor = 0.4)

Xtrain,Xtest,ytrain,ytest=train_test_split(X,y) svc =LinearSVC()

svc.fit(Xtrain,ytrain) ypred =svc.predict(Xtest)

print(accuracy_score(ytest,ypred))

4/4

(6)

Machine Learning avec python

sklearn et circles

Algorithm 5: sklearn and non-linear mapping defphi(x1,x2) :

return np.array([x1,x2,x1∗ ∗2+x2∗ ∗2])

XNew =phi(col1deX,col2deX) /* Comment récupérer des colonnes d’une matrice en Python? */

Xtrain,Xtest,ytrain,ytest=train_test_split(Xnew,y) svc =LinearSVC()

svc.fit(Xtrain,ytrain) ypred =svc.predict(Xtest)

print(accuracy_score(ytest,ypred))

Références

Documents relatifs

There exists (effectively) an integer .R(N) sucå that no positive integer has more tåan rB(If) representations according to

Les méthodes implicites sont plus coûteuses que les méthodes explicites car, si la fonction φ est non linéaire, un problème non linéaire doit être résolu à chaque temps t n+1

Voyons sur trois exemples comment utiliser la fonction odeint du module SciPy pour approcher la solution d’abord d’une EDO ensuite d’un système d’EDO (ce qui inclut les

The case study task consists of searching for publications by the authors that belong to a specific paper. This scenario is much more complicated than the one

[r]

Octave is a numerical linear algebra system (https://www.gnu.org/software/octave/), and function read.octave in package foreign (https://CRAN.R-project.org/package=foreign) can read

permettent de modifier la direction d’un nombre donné de degrés dans le sens trigonométrique (pour left) ou des aiguilles d’une montre (pour right).. Dans l’exemple

Pour cela, nous allons utiliser from sklearn.model_selection import train_test_split.. Cette fonction a l’avantage de randomiser l’ensemble avant de faire

Dans cette partie nous allons voir un premier exemple sur la base de données barbecue vue en TD.. Etudiez le code suivant : import pandas as pd from sklearn

comme la détection, dans un même intervalle de temps de 200 ns, d’une particule alpha et d’un.. rayonnement électromagnétique qui lui est

On the other hand, they favour the idea that transcoding verbal forms into arabic digits operates on representations keeping track of their lexical and syntactic structure, and that

[r]

[r]

[r]

On part de deux abscisses quelconques (pas trop éloignées d'un zéro) et on calcule à chaque étape k, le zéro c k de la sécante (la corde) qui joint les.. Comme dans la méthode

• Leveringen over gans België gratis vanaf &gt;250 flessen., onder de 200 flessen toeslag van 70€.. • Wijnhandel/Horeca/ detailhandel : vraag

Therefore, the analog correlator for electroencephalo- graphy described earlier (6) may be used for this computation by simply substituting a device capable of

Denote by Max 2 (n) the largest number that can be obtained by circular permutation of a n digits code using base-2 representation and by Max 3 (m) the largest number that

Fouvry and Mauduit described in [6] the statistical properties of this set and the goal of this paper is to study more deeply the statistical properties in order to be able

Remarque : si vous travailler avec excel2007 votre fichier aura l’extension xlsx sinon pour excel2003 ca

Since finding the correct settings needs a lot of time and expert knowledge, we developed AutoML tools that can be used out-of-the-box with minimal expertise

[r]

[r]