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
15 changes: 13 additions & 2 deletions learning_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sklearn.linear_model import LogisticRegression

data = load_digits()
print data.DESCR
# print data.DESCR
num_trials = 10
train_percentages = range(5,95,5)
test_accuracies = numpy.zeros(len(train_percentages))
Expand All @@ -16,8 +16,19 @@
# 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
test_accuracies=[]
for j in train_percentages:
train_size = j / 100.0
cumulative_train = 0
cumulative_test = 0
for i in range(10): #do 10 trials
X_train, X_test, y_train, y_test = train_test_split(data.data, data.target, train_size=train_size)
model = LogisticRegression(C=10**-20)
model.fit(X_train, y_train)
cumulative_train = model.score(X_train,y_train) + cumulative_train
cumulative_test = model.score(X_test,y_test) + cumulative_test
test_accuracies.append(cumulative_test)

# TODO: your code here

fig = plt.figure()
plt.plot(train_percentages, test_accuracies)
Expand Down
7 changes: 7 additions & 0 deletions questions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1. It seems like a logarithmic graph - it is increasing but has a downward curve.

2. It seems to be noisiest in the 40-60 range. I would imagine because this is the area where the training set becomes larger than the testing set.

3. It seems to smooth out upwards of 75-100 trials.

4. With a much larger C (10^-1, 10), the graph rises sharply in the 20-30% range, then mellows out a lot. With a very small C (10^-20), the graph shoots up quickly at the beginning then falls down after about 25%.