Algorithm | Used for | Model Code |
Linear Regression | Regression | from sklearn.linear_model import LinearRegression model=LinearRegression() model.fit(X_train,y_train) y_predict=model.predict(X_test) |
Logistic Regression | Classification | from sklearn.linear_model import LogisticRegression model=LogisticRegression() model.fit(X_train,y_train) y_predict=model.predict(X_test) |
Ridge Regression | Regression | from sklearn.linear_model import RidgeCV cv = RepeatedKFold(n_splits=5, n_repeats=3, random_state=1) model = RidgeCV(alphas = np.arange(0.1,10,0.1),cv= cv ,scoring = ‘neg_mean_absolute_error’) model.fit(X_train,y_train) y_predict = model.predict(X_test) |
Lasso Regression | Regression | from sklearn.linear_model import LassoCV from sklearn.model_selection import RepeatedKFold cv = RepeatedKFold(n_splits=5, n_repeats=3, random_state=1) model = LassoCV(alphas=np.arange(0.1,10,0.1),cv=cv ,tol=1) model.fit(X_train,y_train) y_predict = model.predict(X_test) |
KMeans Clustering | Clustering | from sklearn.cluster import KMeans model = KMeans(n_clusters=3, random_state=10) label = model.fit_predict(X) |
DBSCAN Clustering | Clustering | from sklearn.cluster import DBSCAN model = DBSCAN(eps=0.5, min_samples=5) label = model.fit_predict(X) |
Hierarchical Clustering | Clustering | from sklearn.cluster import AgglomerativeClustering model = AgglomerativeClustering(n_clusters = 2,affinity=’euclidean’,linkage=’ward’) label = model.fit_predict(X) |
PCA | Feature selection | from sklearn.decomposition import PCA model = PCA(n_components=5) trs_data = model.fit_transform(data) X = pd.DataFrame(data = trs_data,columns=[‘pca1′,’pca2′,’pca3′,’pca4′,’pca5’]) |
KNN | Classification | from sklearn.neighbors import KNeighborsClassifier model = KNeighborsClassifier(n_neighbors=5) model.fit(X_train,y_train) y_predict=model.predict(X_test) |
KNN | Regression | from sklearn.neighbors import KNeighborsRegressor model = KNeighborsRegressor(n_neighbors=5) model.fit(X_train,y_train) y_predict=model.predict(X_test) |
SVM | Classification | from sklearn.svm import SVC model = SVC() model.fit(X_train, y_test) y_predict=model.predict(X_test) |
SVM | Regression | from sklearn.svm import SVR model = SVR() model.fit(X_train, y_test) y_predict=model.predict(X_test) |
Naïve Bayes | Classification | from sklearn.naive_bayes import MultinomialNB model = MultinomialNB() model.fit(X_train,y_train) y_predict=model.predict(X_test) |
Naïve Bayes | Classification | from sklearn.naive_bayes import BernoulliNB model=BernoulliNB(alpha=0.01) model.fit(X_train,y_train) y_predict=model.predict(X_test) |
Bagging | reduce variance using with ensemble technique | from sklearn.ensemble import BaggingClassifier model = BaggingClassifier(base_estimator=KNN,n_estimators=20) model.fit(X_train,y_train) y_predict = model.predict(X_test) |
Decision Tree | Classification | from sklearn.tree import DecisionTreeClassifier model=DecisionTreeClassifier() model.fit(X_train,y_train) y_predict=model.predict(X_test) |
Decision Tree | Regression | from sklearn.tree import DecisionTreeRegressor model= DecisionTreeRegressor() model.fit(X_train,y_train) y_predict=model.predict(X_test) |
Random Forest | Classification | from sklearn.ensemble import RandomForestClassifier model= RandomForestClassifier(n_estimators=100) model.fit(X_train,y_train) y_predict=model.predict(X_test) |
Random Forest | Regression | from sklearn.ensemble import RandomForestRegressor model = RandomForestRegressor(n_estimators = 100) model.fit(X_train,y_train) y_predict=model.predict(X_test) |
XGBRegressor | Regression | import xgboost as xgb model = xgb.XGBRegressor() y_predict=model.predict(X_test) |