Commit
·
8589bee
1
Parent(s):
7494e9b
Create logisticregression
Browse files- logisticregression +45 -0
logisticregression
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sklearn
|
2 |
+
from sklearn import datasets
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
iris = datasets.load_iris()
|
6 |
+
digits = datasets.load_digits()
|
7 |
+
|
8 |
+
from sklearn.datasets import load_iris
|
9 |
+
iris_data = load_iris()
|
10 |
+
|
11 |
+
print(iris_data.data[0]) # Feature values for first sample
|
12 |
+
print(iris_data.target[0]) # Target value for first sample
|
13 |
+
|
14 |
+
|
15 |
+
# The imputer replaces missing values with the mean
|
16 |
+
|
17 |
+
from sklearn.impute import SimpleImputer
|
18 |
+
|
19 |
+
imputer = SimpleImputer(strategy='mean')
|
20 |
+
imputed_data = imputer.fit_transform(iris_data.data)
|
21 |
+
|
22 |
+
# Feature Scaling
|
23 |
+
|
24 |
+
from sklearn.preprocessing import StandardScaler
|
25 |
+
|
26 |
+
scaler = StandardScaler()
|
27 |
+
scaled_data = scaler.fit_transform(iris_data.data)
|
28 |
+
|
29 |
+
|
30 |
+
# Visualizing the Data
|
31 |
+
|
32 |
+
import matplotlib.pyplot as plt
|
33 |
+
plt.scatter(iris_data.data[:, 0], iris_data.data[:, 1], c=iris_data.target)
|
34 |
+
plt.xlabel('Sepal Length')
|
35 |
+
plt.ylabel('Sepal Width')
|
36 |
+
plt.show()
|
37 |
+
|
38 |
+
|
39 |
+
# Training a Simple Model
|
40 |
+
|
41 |
+
from sklearn.linear_model import LogisticRegression
|
42 |
+
|
43 |
+
model = LogisticRegression()
|
44 |
+
model.fit(scaled_data, iris_data.target)
|
45 |
+
|