Beispiel #1
0
def test(aaron_judge):
    fig, ax = plt.subplots()
    aaron_judge["type"] = aaron_judge["type"].map({"S": 1, "B": 0})
    # print(aaron_judge.type.unique())
    # print(aaron_judge["plate_x"])
    aaron_judge = aaron_judge.dropna(subset=["plate_x", "plate_z", "type"])
    plt.scatter(x=aaron_judge.plate_x,
                y=aaron_judge.plate_z,
                c=aaron_judge.type,
                cmap=plt.cm.coolwarm,
                alpha=0.25)
    training_set, test_set = train_test_split(aaron_judge, random_state=1)
    classifier = SVC(kernel="rbf", gamma=3, C=1)
    classifier.fit(training_set[["plate_x", "plate_z"]], training_set["type"])
    draw_boundary(ax, classifier)
    print(classifier.score(test_set[["plate_x", "plate_z"]], test_set["type"]))
    ax.set_ylim(-2, 6)
    ax.set_xlim(-3, 3)
    plt.show()
from players import aaron_judge, jose_altuve, david_ortiz

fig, ax = plt.subplots()

#print(type(aaron_judge))
#print(aaron_judge.columns)
#print(aaron_judge.columns.unique())
#print(aaron_judge.type)
#print(aaron_judge.type.unique())

aaron_judge['type'] = aaron_judge['type'].map({'S': 1, 'B': 0})
#print(aaron_judge.type.unique())

#print(aaron_judge.plate_x)
#print(len(aaron_judge))
aaron_judge = aaron_judge.dropna(subset=['type', 'plate_x', 'plate_z'])
#print(len(aaron_judge))

y = aaron_judge['type']
plt.scatter(x=aaron_judge['plate_x'],
            y=aaron_judge['plate_z'],
            c=y,
            alpha=0.25,
            cmap=plt.cm.coolwarm)

training_set, validation_set = train_test_split(aaron_judge, random_state=1)
#print(len(aaron_judge))
#print(len(training_set))

classifier = SVC(kernel='rbf', gamma=3, C=1)
#training_data = [training_set['plate_x'],training_set['plate_z']]