This file contains hidden or 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
pip install numpy | |
pip install pandas | |
pip install sklearn |
This file contains hidden or 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
import numpy as np | |
import pandas as pd | |
from sklearn.model_selection import train_test_split | |
from sklearn import preprocessing | |
from sklearn import tree |
This file contains hidden or 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
dataset_url = 'http://mlr.cs.umass.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv' | |
data = pd.read_csv(dataset_url, sep=';') |
This file contains hidden or 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
fixed acidity volatile acidity citric acid residual sugar chlorides \ | |
0 7.4 0.70 0.00 1.9 0.076 | |
1 7.8 0.88 0.00 2.6 0.098 | |
2 7.8 0.76 0.04 2.3 0.092 | |
3 11.2 0.28 0.56 1.9 0.075 | |
4 7.4 0.70 0.00 1.9 0.076 | |
free sulfur dioxide total sulfur dioxide density pH sulphates \ | |
0 11.0 34.0 0.9978 3.51 0.56 | |
1 25.0 67.0 0.9968 3.20 0.68 |
This file contains hidden or 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
y = data.quality | |
X = data.drop('quality', axis=1) |
This file contains hidden or 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
X_train, X_test, y_train, y_test = train_test_split(X, y,test_size=0.2) |
This file contains hidden or 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
X_train: | |
fixed acidity volatile acidity citric acid residual sugar chlorides \ | |
591 6.6 0.39 0.49 1.7 0.070 | |
1196 7.9 0.58 0.23 2.3 0.076 | |
1128 10.0 0.43 0.33 2.7 0.095 | |
640 9.9 0.54 0.45 2.3 0.071 | |
389 9.6 0.38 0.31 2.5 0.096 | |
free sulfur dioxide total sulfur dioxide density pH sulphates \ |
This file contains hidden or 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
X_train_scaled = preprocessing.scale(X_train) | |
print X_train_scaled |
This file contains hidden or 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
After preprocessing: | |
[[-0.53815281 0.63268848 -0.51940197 ..., -0.19976907 -0.92134183 | |
-0.87130124] | |
[-1.05705689 0.46528334 -1.39710129 ..., 1.94678214 0.23712868 | |
1.00404675] | |
[-1.92189703 -0.59494924 -0.15799637 ..., 2.66229921 0.46882278 | |
3.34823175] | |
..., | |
[-0.36518478 2.41834335 -0.36451386 ..., 0.32060698 -1.26888298 |
This file contains hidden or 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
clf=tree.DecisionTreeClassifier() | |
clf.fit(X_train, y_train) |
OlderNewer