Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added TBMachineLearning.pdf
Binary file not shown.
22 changes: 17 additions & 5 deletions learning_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def train_model():
used to train it.
"""
data = load_digits()
num_trials = 10
train_percentages = range(5, 95, 5)
num_trials = 100
train_percentages = range(1, 99, 1)
test_accuracies = numpy.zeros(len(train_percentages))

# train models with training percentages between 5 and 90 (see
Expand All @@ -38,17 +38,29 @@ def train_model():
# variability.
# For consistency with the previous example use
# model = LogisticRegression(C=10**-10) for your learner

for i in range(0,len(train_percentages)):
scores = []
for q in range(0,num_trials):
X_train, X_test, y_train, y_test = train_test_split(data.data, data.target,
train_size=train_percentages[i]/100)
model = LogisticRegression(C=10**-10)
model.fit(X_train, y_train)
scores.append(model.score(X_train, y_train))

# TODO: your code here
test_accuracies[i] = sum(scores)/float(len(scores))
# print("Train accuracy %f" %model.score(X_train, y_train))
# print("Test accuracy %f"%model.score(X_test, y_test))

fig = plt.figure()
plt.plot(train_percentages, test_accuracies)
plt.title('Digit Learning with '+str(num_trials)+' Trials')
plt.xlabel('Percentage of Data Used for Training')
plt.ylabel('Accuracy on Test Set')
plt.show()


if __name__ == "__main__":
# Feel free to comment/uncomment as needed
display_digits()
# train_model()
# display_digits()
train_model()