Having $(X1,y1), (X2,y2), (X2,y2)$ saved in a dictionary:
dictionary = {X1:y1, X2:y2, X3:y3}
accuracies = []
for k,v in dictionary.items():
X_train, X_test, y_train, y_test = train_test_split(k, v,
test_size=0.25, shuffle=False)
logreg = LogisticRegression()
logreg.fit(X_train,y_train)
y_pred = logreg.predict(X_test)
accuracies.append(metrics.accuracy_score(y_test, y_pred))
But it's not really a good way especially when the datasets are too big.
So:
accuracies = []
for i in range(1,4):
X = 'X{}'.format(i)
y = 'y{}'.format(i)
X_train, X_test, y_train, y_test = train_test_split(vars()[X], vars()[y],
test_size=0.25, shuffle=False)
logreg = LogisticRegression()
logreg.fit(X_train,y_train)
y_pred = logreg.predict(X_test)
accuracies.append(metrics.accuracy_score(y_test, y_pred))
Note:
in order to access the varibale names which are different in a small part, like here for X1,X2,..., we can use the mentioned method:
import numpy as np
X1= np.arange(1,10)
y1=[i**2 for i in X1]
X2= np.arange(-5,5)
y2=[i**2 for i in X2]
for i in range(1,3):
X = 'X{}'.format(i)
y = 'y{}'.format(i)
print('X_{}'.format(i) , vars()[X])
print('y_{}'.format(i) , vars()[y])
Output:
X_1 [1 2 3 4 5 6 7 8 9]
y_1 [1, 4, 9, 16, 25, 36, 49, 64, 81]
X_2 [-5 -4 -3 -2 -1 0 1 2 3 4]
y_2 [25, 16, 9, 4, 1, 0, 1, 4, 9, 16]