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
11 changes: 11 additions & 0 deletions Answer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1.
The Accuracy on Test Set increases as Percentage of Data Used for Training increases, but the slope keeps decreasing slightly.
2.
When percentage used of data is relatively small, the curve is noisier. Standard deviation is relatively high when the dataset is relatively small.
3.
I set num_trails as 1000 and it looks smooth, but still need more to make it perfectly smooth
4.
As C gets bigger, the bending of learning curve becomes more obvious. C is the 'inverse of regularization strength', so bigger C means weaker regularization, which make the graph smoother.



17 changes: 11 additions & 6 deletions learning_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@

data = load_digits()
print data.DESCR
num_trials = 10
num_trials = 1000
train_percentages = range(5,95,5)
test_accuracies = numpy.zeros(len(train_percentages))

# train a model with training percentages between 5 and 90 (see train_percentages) and evaluate
# the resultant accuracy.
# You should repeat each training percentage num_trials times to smooth out variability
# for consistency with the previous example use model = LogisticRegression(C=10**-10) for your learner

# TODO: your code here
curve_y = []
model = LogisticRegression(C=10**-10)
for i in train_percentages:
score = []
for j in range(num_trials):
X_train, X_test, Y_train, Y_test = train_test_split(data.data, data.target, train_size=i)
model.fit(X_train, Y_train)
score.append(model.score(X_test, Y_test))
test_accuracies[i/5-1] = sum(score)/num_trials


fig = plt.figure()
plt.plot(train_percentages, test_accuracies)
Expand Down