An example of fitting and testing a model with your data stored in a list is below:
# Import some libraries
from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
# Make some generic data
first_data, first_classes = make_classification(n_samples=100, n_features=5, random_state=1)
second_data, second_classes = make_classification(n_samples=100, n_features=5, random_state=2)
third_data, third_classes = make_classification(n_samples=100, n_features=5, random_state=3)
# Save data and classes into a list
data = [first_data, second_data, third_data]
classes = [first_classes, second_classes, third_classes]
# Declare a logistic regression instance
model = LogisticRegression()
for i in range(len(data)):
# Split data into training and test
X_train, X_test, y_train, y_test = train_test_split(data[i], classes[i], test_size=0.15)
# Fit the model
model.fit(X_train, y_train)
# Print results
print("{} Dataset | Score: {}".format(i+1, model.score(X_test, y_test)))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…