from matplotlib import pyplot as plt
import seaborn as sb
import pandas as pd
import numpy as np
ds = sb.load_dataset("iris")
print(
"Number of attributes:", ds.shape[1],
"\nNumber of patterns: ", ds.shape[0]
)
x = pd.DataFrame()
for i in ds.species.unique():
x = x.append(ds.loc[ds["species"] == i].head(4))
x
sb.scatterplot(x="sepal_length",
y="petal_length",
data=x,
hue="species",
style="species")
sb.scatterplot(x="sepal_length",
y="petal_length",
data=ds,
hue="species",
style="species")
t = np.zeros(ds.shape[0])
ans = True
while ans:
choice = input(
"1. Διαχωριςμόσ Iris-setosa από ( Iris-versicolor και Iris-virginica)\n"
"2. Διαχωριςμόσ Iris-virginica από ( Iris-setosa και Iris-versicolor)\n"
"3. Διαχωριςμόσ Iris-versicolor από ( Iris-setosa και Iris-virginica)\n"
)
map_dict = dict()
if choice == "1":
map_dict = {"setosa": 1, "versicolor":0, "virginica":0}
elif choice == "2":
map_dict = {"setosa": 0, "versicolor":1, "virginica":0}
elif choice == "3":
map_dict = {"setosa": 0, "versicolor":0, "virginica":1}
for i in range(len(t)):
t[i] = map_dict[ds["species"][i]]
ans = False
print(t)
ds["New_column"] = 1
xtrain = pd.DataFrame()
for i in ds.species.unique():
xtrain = xtrain.append(ds.loc[ds["species"] == i].head(40))
xtrain.head()
xtest = pd.DataFrame()
for i in ds.species.unique():
xtest = xtest.append(ds.loc[ds["species"] == i].tail(10))
xtest.head()
ttrain = np.zeros(len(xtrain.index))
j=0
for i in xtrain.index:
ttrain[j] = t[i]
j+=1
ttrain
ttest = np.zeros(len(xtest.index))
j=0
for i in xtest.index:
ttest[j] = t[i]
j+=1
ttest
plot = sb.scatterplot(x="sepal_length",
y="petal_length",
data=xtrain)
plot = sb.scatterplot(x="sepal_length",
y="petal_length",
data=xtest)
choice2 = input(
"1. Υλοποίηση με Perceptron\n"
"2. Υλοποίηση με Adaline\n"
"3. Υλοποίηση με Λύση Ελάχιστων Τετραγώνων\n"
"4. Επιστροφή στο αρχικό Menu\n"
)
if choice2 == "1":
perceptron()
elif choice2 == "2":
adaline()
elif choice2 == "3":
lsq()
elif choice == "4":
print("Back to menu")
ans = input(
"Do you want to continue (y/n)?\n"
)
if ans == "y":
ans = True
else:
ans = False
def perceptron():
print("perceptron")
def adaline():
print("adaline")
def lsq():
print("lsq")
ro=0
while(ro<10):
ro+=1
if ro==5:
continue
print(ro)
from matplotlib import pyplot as plt
import seaborn as sb
import pandas as pd
import numpy as np
def perceptron():
print("perceptron")
def adaline():
print("adaline")
def lsq():
print("lsq")
def menu(menu_text, valid_options):
menu_text = (
"========================================\n"
+ menu_text
+ "\n========================================\n"
)
choice = int(input(menu_text))
while True:
if choice not in valid_options:
choice = int(input(menu_text))
else:
return choice
def main():
ds = sb.load_dataset("iris")
print(
"Number of attributes:", ds.shape[1],
"\nNumber of patterns: ", ds.shape[0]
)
sb.scatterplot(x="sepal_length",
y="petal_length",
data=ds,
hue="species",
style="species")
plt.show()
t = np.zeros(ds.shape[0])
ans = True
while ans:
choice = menu(
"1. Διαχωριςμόσ Iris-setosa από ( Iris-versicolor και Iris-virginica)\n"
"2. Διαχωριςμόσ Iris-virginica από ( Iris-setosa και Iris-versicolor)\n"
"3. Διαχωριςμόσ Iris-versicolor από ( Iris-setosa και Iris-virginica)",
[1,2,3]
)
map_dict = dict()
if choice == 1:
map_dict = {"setosa": 1, "versicolor":0, "virginica":0}
elif choice == 2:
map_dict = {"setosa": 0, "versicolor":1, "virginica":0}
else:
map_dict = {"setosa": 0, "versicolor":0, "virginica":1}
for i in range(len(t)):
t[i] = map_dict[ds["species"][i]]
ds["New_column"] = 1
xtrain = pd.DataFrame()
for i in ds.species.unique():
xtrain = xtrain.append(ds.loc[ds["species"] == i].head(40))
xtest = pd.DataFrame()
for i in ds.species.unique():
xtest = xtest.append(ds.loc[ds["species"] == i].tail(10))
ttrain = np.zeros(len(xtrain.index))
j=0
for i in xtrain.index:
ttrain[j] = t[i]
j+=1
ttest = np.zeros(len(xtest.index))
j=0
for i in xtest.index:
ttest[j] = t[i]
j+=1
plot = sb.scatterplot(x="sepal_length",
y="petal_length",
data=xtrain)
plot = sb.scatterplot(x="sepal_length",
y="petal_length",
data=xtest)
plt.show()
choice2 = menu(
"1. Υλοποίηση με Perceptron\n"
"2. Υλοποίηση με Adaline\n"
"3. Υλοποίηση με Λύση Ελάχιστων Τετραγώνων\n"
"4. Επιστροφή στο αρχικό Menu",
[1,2,3,4]
)
if choice2 == 1:
perceptron()
elif choice2 == 2:
adaline()
elif choice2 == 3:
lsq()
else:
continue
if menu("1.Again\n2.exit\n", [1,2]) == 1:
ans = True
else:
ans = False
I can't do sh$t
# variables
maxepochs = int(input("Max: "))
beta = float(input("Beta: "))
def perceptron(xtrain, ttrain, maxepochs, beta)