Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to write for loop?
#2
model = XGBClassifier()
np.random.seed(32) # this makes results reproducible; comment this line if needed
accuracies = []
for counter in range(100):
    X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.3) # if random_state parameter is removed, train_test_split will use random seed value from the numpy package
    model.fit(X_train, y_train)
    y_pred = model.predict(X_test)
    accuracy = accuracy_score(y_test, y_pred.round())
    accuracies.append(accuracy)
print('Total number of splittings: ', len(accuracies), 'Mean accuracy score: ', np.mean(accuracies), 'std.dev.: ', np.std(accuracies))
Reply


Messages In This Thread
How to write for loop? - by sandy49992 - Aug-29-2018, 04:25 PM
RE: How to write for loop? - by scidam - Aug-30-2018, 01:09 AM
RE: How to write for loop? - by sandy49992 - Aug-30-2018, 11:27 AM
RE: How to write for loop? - by sandy49992 - Aug-30-2018, 02:49 PM
RE: How to write for loop? - by sandy49992 - Aug-30-2018, 04:52 PM
RE: How to write for loop? - by scidam - Aug-31-2018, 12:31 AM
RE: How to write for loop? - by sandy49992 - Sep-04-2018, 03:54 PM
RE: How to write for loop? - by sandy49992 - Sep-21-2018, 01:47 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020