Skip to content

Instantly share code, notes, and snippets.

@Neeratyoy
Created October 25, 2019 15:30
Show Gist options
  • Save Neeratyoy/ad9a645b319e60cab543eaaf8948c92c to your computer and use it in GitHub Desktop.
Save Neeratyoy/ad9a645b319e60cab543eaaf8948c92c to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"from sklearn import datasets\n",
"from sklearn.svm import SVC\n",
"from sklearn.ensemble import RandomForestClassifier\n",
"from sklearn.model_selection import cross_val_score"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(150, 4) (150,)\n"
]
}
],
"source": [
"# Loading Iris dataset\n",
"X, y = datasets.load_iris(return_X_y=True)\n",
"print(X.shape, y.shape)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Initializing a Random Forest with \n",
"# arbitrary hyperparameters\n",
"# max_depth kept as 2 since Iris has\n",
"# only 4 features\n",
"clf = RandomForestClassifier(n_estimators=10, max_depth=2)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Mean score : 0.95333\n"
]
}
],
"source": [
"scores = cross_val_score(clf, X, y, cv=5, scoring='accuracy')\n",
"print(\"Mean score : {:.5f}\".format(scores.mean()))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
@sjhsbhqf
Copy link

sjhsbhqf commented Feb 5, 2022

good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment