예제 #1
0
data = pd.read_csv("rodents.csv", delimiter=";", names = headers,header=None, skiprows=1)

data.dropna()

# Convert gender to 0 or 1
label_enc =preprocessing.LabelEncoder()
data['typez'] = data['typez'].apply(lambda x: 1 if str(x).strip() == 'rat' else -1)
data.head()

y = data["typez"]


rodents_np = data.to_numpy()
rodents_fmt = [(rodents[:2], rodents[2]) for rodents in rodents_np]
weights,_ = pc.pla(rodents_fmt)

print("-------",weights)

colors = 'rg'
for target, name in (zip([1,-1],['rat','mouse'])):
    #print(idx)
    d = data[data['typez']==target]
    if(target == 1):
        color_idx = target
    else:
        color_idx = 0
    

print(data['typez'])
plt.scatter(data['weight'],data['height'],c=colors[color_idx], label=name)
예제 #2
0
    return output


print(perceptron([1, 2, 3, 4, 5], [1, 1, 2, 1, 1]))
#part 2
# 1 Make a new scatter plot with datapoints of weights vs heights. Choose different colors for rats and mice
import pandas as pd
import perceptron as pc
rodent = pd.read_csv("rodents.csv", sep=';')
rodent = rodent.dropna()
rodent["type"] = rodent["type"].apply(lambda x: 1
                                      if str(x).strip() == "rat" else -1)
#print(rodent)
rodent_np = rodent.to_numpy()
rodent_fmt = [(data[:2], data[2]) for data in rodent_np]
weights = pc.pla(rodent_fmt)
#print(weights)
colors = "rb"
for target, name in (zip([1, -1], ["rat", "mouse"])):
    #print(idx)
    data = rodent[rodent["type"] == target]
    color_idx = target if target == 1 else 0
    plt.scatter(data["weight"],
                data["height"],
                c=colors[color_idx],
                label=name)  #

plt.title("mesures for mice and rats")
plt.xlabel("weight")
plt.ylabel("height")
plt.legend()