Skip to content

Commit

Permalink
Create algorithms.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored May 10, 2024
1 parent f915b12 commit 61419d2
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions machine_learning/algorithms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from sklearn.cluster import KMeans
from sklearn.decomposition import PCA
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC

class Algorithms:
@staticmethod
def k_means(X, k):
return KMeans(n_clusters=k).fit(X)

@staticmethod
def pca(X, n_components):
return PCA(n_components=n_components).fit(X)

@staticmethod
def random_forest(X, y, n_estimators=100, max_depth=None):
return RandomForestClassifier(n_estimators=n_estimators, max_depth=max_depth).fit(X, y)

@staticmethod
def logistic_regression(X, y, penalty='l2', C=1.0):
return LogisticRegression(penalty=penalty, C=C).fit(X, y)

@staticmethod
def k_nearest_neighbors(X, y, n_neighbors=5):
return KNeighborsClassifier(n_neighbors=n_neighbors).fit(X, y)

@staticmethod
def svm(X, y, kernel='linear', C=1.0):
return SVC(kernel=kernel, C=C).fit(X, y)

0 comments on commit 61419d2

Please sign in to comment.