forked from rasbt/python-machine-learning-book-3rd-edition
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Type : feat. Abstract: * Draw data plot
- Loading branch information
JackFunfia
committed
May 24, 2023
1 parent
b9ec514
commit eca7da5
Showing
2 changed files
with
59 additions
and
5 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import matplotlib.pyplot as plt | ||
import pandas as pd | ||
import requests | ||
import io | ||
import os | ||
from perceptron import Perceptron | ||
PATH = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data" | ||
|
||
with requests.get(PATH) as response: | ||
raw_data = response.text | ||
|
||
# s = os.path.join("https://archive.ics.uci.edu", "ml", | ||
# "machine-learning-databases", | ||
# "iris", "iris.data") | ||
s = os.path.join(PATH) | ||
|
||
df = pd.read_csv(s) | ||
# print(df.tail()) | ||
# string_data = io.StringIO(raw_data) | ||
# | ||
# df = pd.read_csv(string_data, header=None, encoding="utf-8") | ||
# | ||
# print(df.tail()) | ||
|
||
import matplotlib.pyplot as plot | ||
import numpy as np | ||
|
||
y = df.iloc[:, 4].values | ||
y = np.where(y == "Iris-setosa", -1, 1) | ||
|
||
X = df.iloc[:, [0, 2, 4]].values | ||
setosa_array = X[(X[:, 2] == "Iris-setosa")] | ||
virginica_array = X[(X[:, 2] == "Iris-virginica")] | ||
versicolor_array = X[(X[:, 2] == "Iris-versicolor")] | ||
|
||
plt.scatter(setosa_array[:, 0], setosa_array[:, 1], | ||
color="red", marker="o", label="setosa") | ||
plt.scatter(virginica_array[:, 0], virginica_array[:, 1], | ||
color="blue", marker="x", label="virginica") | ||
plt.scatter(versicolor_array[:, 0], versicolor_array[:, 1], | ||
color="green", marker="^", label="versicolor") | ||
|
||
plt.xlabel("sepal length [cm]") | ||
plt.ylabel("petal length [cm]") | ||
plt.legend(loc="upper left") | ||
plt.show() | ||
|
||
ppn = Perceptron(eta=0.1, n_iter=10) | ||
# ppn.fit(X, y) |