0% found this document useful (0 votes)
4 views2 pages

Cross Validation3

The document contains Python code for loading the Iris dataset and performing various machine learning tasks using Support Vector Machines (SVM). It includes splitting the dataset into training and testing sets, fitting the model, scoring the model's accuracy, and using cross-validation techniques. Additionally, it demonstrates the use of ShuffleSplit and cross_val_predict for model evaluation.

Uploaded by

shumbamhinii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Cross Validation3

The document contains Python code for loading the Iris dataset and performing various machine learning tasks using Support Vector Machines (SVM). It includes splitting the dataset into training and testing sets, fitting the model, scoring the model's accuracy, and using cross-validation techniques. Additionally, it demonstrates the use of ShuffleSplit and cross_val_predict for model evaluation.

Uploaded by

shumbamhinii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import numpy as np

from sklearn.model_selection import train_test_split


from sklearn import datasets
from sklearn import svm

iris=datasets.load_iris()
iris.data.shape,iris.target.shape

#train_test_split?

X_train,X_test,y_train,y_test=train_test_split(iris.data,iris.target,test_size=0.2

X_train.shape,X_test.shape,y_train.shape,y_test.shape

clf=svm.SVC(kernel='linear',C=1)

clf.fit(X_train,y_train)

clf.score(X_test,y_test)

clf.score(X_train,y_train)

from sklearn.model_selection import cross_val_score


#cross_val_score?

clf=svm.SVC(kernel='linear',C=1)
scores=cross_val_score(clf,iris.data,iris.target,cv=5)
scores

print('Accuracy: %0.2f(+/- %0.2f)'% (scores.mean(),scores.std()*2))

from sklearn import metrics


scores=cross_val_score(clf,iris.data,iris.target,cv=5,scoring='f1_macro')
scores
from sklearn.model_selection import ShuffleSplit
#ShuffleSplit?

n_samples=iris.data.shape[0]
cv=ShuffleSplit(n_splits=3,test_size=0.3,random_state=0)
cross_val_score(clf,iris.data,iris.target,cv=cv)

from sklearn.model_selection import cross_val_predict


#cross_val_predict?

predicted=cross_val_predict(clf,iris.data,iris.target,cv=10)
predicted.shape

You might also like