Skip to content

Instantly share code, notes, and snippets.

@MarwanDebbiche
Last active August 8, 2019 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarwanDebbiche/6cf583f7a5d6d5e9e3f9b36e1fc1f20b to your computer and use it in GitHub Desktop.
Save MarwanDebbiche/6cf583f7a5d6d5e9e3f9b36e1fc1f20b to your computer and use it in GitHub Desktop.
Iris Classification
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import joblib"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>petal length (cm)</th>\n",
" <th>petal width (cm)</th>\n",
" <th>sepal length (cm)</th>\n",
" <th>sepal width (cm)</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.5</td>\n",
" <td>0.2</td>\n",
" <td>5.1</td>\n",
" <td>3.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" petal length (cm) petal width (cm) sepal length (cm) sepal width (cm)\n",
"0 1.5 0.2 5.1 3.0"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"new_iris_flower = pd.DataFrame([\n",
" {\n",
" \"sepal length (cm)\": 5.1,\n",
" \"sepal width (cm)\": 3.,\n",
" \"petal length (cm)\": 1.5,\n",
" \"petal width (cm)\": 0.2,\n",
" }\n",
"])\n",
"\n",
"new_iris_flower"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"with open(\"iris_classifier.joblib\", \"rb\") as f:\n",
" clf = joblib.load(f)\n",
"\n",
"with open(\"iris_classifier_features.joblib\", \"rb\") as f:\n",
" features = joblib.load(f)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['setosa'], dtype=object)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"clf.predict(new_iris_flower[features])"
]
}
],
"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.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment