'Object declaration in a loop for different ML models

Can anyone help me out, how can I perform the following task? I am getting an error TypeError: 'str' object is not callable

models = ['LogisticRegression','RandomForestClassifier','KNeighborsClassifier' ,'DecisionTreeClassifier','SVC']
acc = {}
for model in models:
  m = model()
  m.fit(X_train_t_scaled, y_train_t)
  y_pred = m.predict(X_val_t_scaled)
  acc[model] = accuracy_score(y_val_t, y_pred)


Solution 1:[1]

Try:

from sklearn.ensemble import RandomForestRegressor
models = [RandomForestRegressor]
for model in models:
    ...

Don't forget to

pip install sklearn

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 modus ponies