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 :: telnet via jump host using python 
Python :: how to use colorama 
Python :: split multiple times 
Python :: migrate using other database django 
Python :: sum of 1 to n number in python 
Python :: xaxis matplotlib 
Python :: python get square root 
Python :: palindrome Rearranging python one line 
Python :: count number of occurrences of all elements in list python 
Python :: how to run commands in repl.ot 
Python :: open csv file in python 
Python :: 1052 uri solution 
Python :: pandas scatter plot with different colors 
Python :: static dirs django 
Python :: how to get user ip in python 
Python :: Import "flask" could not be resolved 
Python :: tuple in godot 
Python :: Resource punkt not found. Please use the NLTK Downloader to obtain the resource: 
Python :: python sort 2d list 
Python :: log base in python 
Python :: sqlalchemy datetime default now create table 
Python :: python keyboard press 
Python :: all characters python 
Python :: forbidden (csrf cookie not set.) django rest framework 
Python :: how to sort a column with mixed text number 
Python :: python sorting array without inbuilt sort 
Python :: django queryset get all distinct 
Python :: how to make a forever loop in python 
Python :: jupyter notebook change default directory 
Python :: trimming spaces in string python 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =