Created
June 8, 2018 04:57
-
-
Save orleika/929fe28b763fc25dda081c83a837f5b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"0.00984440500563\n", | |
"2.36577968333\n", | |
"[ 5.11136902]\n", | |
"quality 5.0\n", | |
"Name: 0, dtype: float64\n" | |
] | |
} | |
], | |
"source": [ | |
"import pandas as pd\n", | |
"from sklearn.linear_model import ElasticNet\n", | |
"from sklearn.linear_model import ElasticNetCV\n", | |
"\n", | |
"df = pd.read_csv('winequality-red.csv')\n", | |
"train_label = df[1:][['fixed acidity', 'volatile acidity', 'citric acid', 'chlorides', 'free sulfur dioxide', 'total sulfur dioxide', 'density', 'pH', 'sulphates', 'alcohol']]\n", | |
"X = train_label.values\n", | |
"train_result = df[1:][['quality']]\n", | |
"y = train_result.values.flatten()\n", | |
"test_label = df.iloc[0][['fixed acidity', 'volatile acidity', 'citric acid', 'chlorides', 'free sulfur dioxide', 'total sulfur dioxide', 'density', 'pH', 'sulphates', 'alcohol']].values\n", | |
"test_result = df.iloc[0][['quality']]\n", | |
"\n", | |
"# alpha 1.0 ElasticNet\n", | |
"# regr = ElasticNet(alpha=.1)\n", | |
"# regr.fit(X, y)\n", | |
"# print(regr.coef_)\n", | |
"# print(regr.intercept_)\n", | |
"# print(regr.predict([test_label]))\n", | |
"# print(test_result)\n", | |
"\n", | |
"# gridsearch for alpha\n", | |
"regr = ElasticNetCV(cv=5, random_state=0)\n", | |
"regr.fit(X, y)\n", | |
"print(regr.alpha_)\n", | |
"print(regr.intercept_)\n", | |
"print(regr.predict([test_label]))\n", | |
"print(test_result)" | |
] | |
} | |
], | |
"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.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://archive.ics.uci.edu/ml/datasets/Wine