Skip to content
Snippets Groups Projects
Commit d18871dd authored by Nicolas Barthes's avatar Nicolas Barthes
Browse files

LWPLSR as a documented class

parent 176f2ecf
No related branches found
No related tags found
No related merge requests found
...@@ -8,4 +8,7 @@ This workflow aims at ... ...@@ -8,4 +8,7 @@ This workflow aims at ...
## Clustering ## Clustering
[K-Means](Clustering.md#k-means-clustering) [K-Means](Clustering.md#k-means-clustering)
[HDBSCAN](Clustering.md#hdbscan-clustering) [HDBSCAN](Clustering.md#hdbscan-clustering)
\ No newline at end of file
## Models Creation
[lwPlsR from Jchemo (Julia)](model_creation.md)
\ No newline at end of file
# Models creation
## PLSR from Pinard (scikit learn)
::: src.Class_Mod.KMEANS_.Sk_Kmeans
## lwPlsR from Jchemo (Julia)
::: src.Class_Mod.LWPLSR_.LWPLSR
\ No newline at end of file
...@@ -4,6 +4,7 @@ nav: ...@@ -4,6 +4,7 @@ nav:
- Home: 'index.md' - Home: 'index.md'
- Dimensionality Reduction: 'Dimensionality_Reduction.md' - Dimensionality Reduction: 'Dimensionality_Reduction.md'
- Clustering Methods: 'Clustering.md' - Clustering Methods: 'Clustering.md'
- Models Creation: 'model_creation.md'
theme: theme:
......
...@@ -132,7 +132,8 @@ class Hdbscan: ...@@ -132,7 +132,8 @@ class Hdbscan:
dist_function (func): function to determine distance between objects dist_function (func): function to determine distance between objects
func args must be [np.array, np.array] where each array is a point func args must be [np.array, np.array] where each array is a point
Returns: mutual_reachability (float) Returns:
mutual_reachability (float)
mutual reachability between points i and j mutual reachability between points i and j
""" """
......
from Packages import * from Packages import *
from Class_Mod.Miscellaneous import * from Class_Mod.Miscellaneous import *
def LWPLSR(x_train, x_test, y_train, y_test): class LWPLSR:
# prepare to send dataframes to julia and Jchemo """
Main.x_train,Main.y_train,Main.x_test,Main.y_test = x_train, y_train, x_test, y_test The UMAP dimension reduction algorithm from scikit learn
Main.eval(""" """
#convert python pd.dataframes to julia dataframes def __init__(self, x_train, x_test, y_train, y_test):
x_train_j = Main.x_train |> Pandas.DataFrame|> DataFrames.DataFrame; """Initiate the LWPLSR and prepare data for Julia computing."""
y_train_j = Main.y_train |> Pandas.DataFrame|> DataFrames.DataFrame; self.x_train, self.y_train, self.x_test, self.y_test = x_train, x_test, y_train, y_test
x_test_j = Main.x_test |> Pandas.DataFrame|> DataFrames.DataFrame; # prepare to send dataframes to julia and Jchemo
y_test_j = Main.y_test |> Pandas.DataFrame|> DataFrames.DataFrame; self.Main.x_train,self.Main.y_train,self.Main.x_test,self.Main.y_test = self.x_train, self.y_train, self.x_test, self.y_test
# Compute model
nlvdis = 5 ; metric = :mah def Jchemo_lwplsr(self):
h = 1 ; k = 200 ; nlv = 15 #; scal = true """Send data to Julia to compute lwplsr.
mod = Main.Jchemo.model(Main.Jchemo.lwplsr; nlvdis, metric, h, k, nlv)
Main.Jchemo.fit!(mod, X_train_j, y_train_j) Args:
# predictions on test data calculation self.Main.x_train (DataFrame):
res = Main.Jchemo.predict(mod, X_test_j) ; self.Main.y_train (DataFrame):
score = Main.Jchemo.rmsep(res.pred, y_test_j) self.Main.x_test (DataFrame):
resjp = Pandas.DataFrame(res.pred); self.Main.y_test (DataFrame):
""")
score = Main.score Returns:
predicted_results_on_test = pd.DataFrame(Main.resjp) self.scores (DataFrame): various metrics and scores
return score, predicted_results_on_test self.predicted_results_on_test (DataFrame):
\ No newline at end of file """
# launch Julia Jchemo lwplsr
Main.eval("""
#convert python pd.dataframes to julia dataframes
x_train_j = self.Main.x_train |> Pandas.DataFrame|> DataFrames.DataFrame;
y_train_j = self.Main.y_train |> Pandas.DataFrame|> DataFrames.DataFrame;
x_test_j = self.Main.x_test |> Pandas.DataFrame|> DataFrames.DataFrame;
y_test_j = self.Main.y_test |> Pandas.DataFrame|> DataFrames.DataFrame;
# Compute model
nlvdis = 5 ; metric = :mah
h = 1 ; k = 200 ; nlv = 15 #; scal = true
mod = Main.Jchemo.model(Main.Jchemo.lwplsr; nlvdis, metric, h, k, nlv)
Main.Jchemo.fit!(mod, X_train_j, y_train_j)
# predictions on test data calculation
res = Main.Jchemo.predict(mod, X_test_j) ;
scores = Main.Jchemo.mse(res.pred, y_test_j)
scoresjp = Pandas.DataFrame(scores);
resjp = Pandas.DataFrame(res.pred);
""")
self.scores = self.Main.scoresjp
self.predicted_results_on_test = pd.DataFrame(self.Main.resjp)
@property
def scores_(self):
return self.scores, self.predicted_results_on_test
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment