Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

cross validation python

# SVC: support vector classifier (one of the "built-in" classifiers in scikit-learn)
# X, y: array-like representing input and target variables
# X.shape = (N, num_of_features)
# y.shape = (N, 1) in case of classification problem

from sklearn.model_selection import cross_val_score
clf = svm.SVC(kernel='linear', C=1, random_state=42)
scores = cross_val_score(clf, X, y, cv=5) # 5-fold cross validation
Comment

python cross validation

from sklearn.model_selection import cross_val_score
scores = cross_val_score(model   # Ridge(alpha=1)
                       , X_train # scaler.fit_transform(x_train)
                       , y_train # scaler.fit_transform(y_train)
                       , scoring='neg_mean_squared_error' # depends on model more at https://scikit-learn.org/stable/modules/model_evaluation.html
                       , cv=5)   # 5 fold cross validation
mean(scores) # negMSE (higher=better), adj hyper params to optimize 
model.fit(x_train, y_train)      # make sure to fit the model again after 
y_final_test_pred = model.predict(x_test) # Final predictions
mean_squared_error(y_test, y_final_test_pred) # Final MSE on 'new' data
Comment

PREVIOUS NEXT
Code Example
Python :: python how to get user input 
Python :: print specific list item python 
Python :: python hide details 
Python :: search dictionary for value 
Python :: python lock using a file 
Python :: python profiler 
Python :: how to put in code to download discord py 
Python :: km/h to mph python 
Python :: discord.py read embed on message 
Python :: skip to next iteration in for loop python 
Python :: otp generation in python 
Python :: ad background image with tkinter 
Python :: ComplexWarning: Casting complex values to real discards the imaginary part 
Python :: pandas return specific row 
Python :: django orm sum 
Python :: python if in list multiple 
Python :: replace values in a column by condition python 
Python :: concat columns pandas dataframe 
Python :: what is instance variable in python 
Python :: mailchimp send email python 
Python :: progressbar time in python 
Python :: odd or even in python 
Python :: Date Time split in python 
Python :: what if we multiply a string in python 
Python :: django view 
Python :: selenium get cookies python 
Python :: how to make a def in python 
Python :: pyton filter 
Python :: python how to get the folder name of a file 
Python :: binary to decimal conversion python 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =