Missing Attribute Values: Yes
For Each Attribute: (all numeric-valued)
1. Number of times pregnant
2. Plasma glucose concentration a 2 hours in an oral glucose tolerance test
3. Diastolic blood pressure (mm Hg)
4. Triceps skin fold thickness (mm)
5. 2-Hour serum insulin (mu U/ml)
6. Body mass index (weight in kg/(height in m)^2)
7. Diabetes pedigree function
8. Age (years)
9. Class variable (0 or 1)
目的は最初の8つの変数を使用して9を予測することです。
インスタンスの総数:768
Class Distribution: (class value 1 is interpreted as "tested positive for
diabetes")
Class Value Number of instances
0 500
1 268
データ読み出し
import numpy as np
import urllib
# url with dataset
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/pima-indians-diabetes/pima-indians-diabetes.data"
# download the file
raw_data = urllib.urlopen(url)
# load the CSV file as a numpy matrix
dataset = np.loadtxt(raw_data, delimiter=",")
# separate the data from the target attributes
X = dataset[:,0:8]
y = dataset[:,8]
データ前処理
勾配法の大部分(ほとんど全ての機械学習にアルゴリズムは、データスケーリングに対して非常に敏感です)。アルゴリズムを実行する前に、の正規化、またはの標準化のいずれかを実行する必要があります。標準化では、データの前処理が行われ、その後、各フィーチャには平均0と1の分散があります。 Scikit-Learnライブラリは、このための既成の関数を提供しています。
from sklearn import preprocessing
# normalize the data attributes
normalized_X = preprocessing.normalize(X)
# standardize the data attributes
standardized_X = preprocessing.scale(X)
Scikit-Learnは、機械学習のすべての基本アルゴリズムを実装しています。
ロジスティック回帰
from sklearn import metrics
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.fit(X, y)
print(model)
# make predictions
expected = y
predicted = model.predict(X)
# summarize the fit of the model
print(metrics.classification_report(expected, predicted))
print(metrics.confusion_matrix(expected, predicted))
希望、これは便利です: 次の例を試してみてください。
コードは次のようになります。 –
ようこそ!あなたは誰かにあなたのためのコードを書くよう求めているようです。 Stack Overflowは、コード作成サービスではなく、Q&Aサイトです。効果的な質問を書く方法については、こちらをご覧ください(http://stackoverflow.com/help/how-to-ask)。 – JGreenwell
あなたはどのモデリングソフトウェア/モジュールを使用していますか? – martineau