Skip to content
Snippets Groups Projects
Commit d6eb78a9 authored by DIANE's avatar DIANE
Browse files

AFFINITY PROPAGATION

parent 246b5636
No related branches found
No related tags found
No related merge requests found
from Packages import *
class AP:
def __init__(self, X):
## input matrix
self.__x = np.array(X)
# Fit PCA model
self.M = AffinityPropagation(damping=0.5, max_iter=200, convergence_iter=15, copy=True, preference=None,
affinity='euclidean', verbose=False, random_state=None)
self.M.fit(self.__x)
self.yp = self.M.predict(self.__x)+1
@property
def fit_optimal_(self):
clu = [f'cluster#{i}' for i in self.yp]
return self.__x, clu, self.M.cluster_centers_
\ No newline at end of file
......@@ -13,4 +13,5 @@ from .DxReader import DxRead, read_dx
from .HDBSCAN_Clustering import Hdbscan
from .SK_PLSR_ import PlsR
from .PLSR_Preprocess import PlsProcess
from .NMF_ import Nmf
\ No newline at end of file
from .NMF_ import Nmf
from .Ap import AP
\ No newline at end of file
from Packages import *
from Class_Mod import PlsR, LinearPCA, Umap, find_col_index, PinardPlsr, Nmf
from Class_Mod import PlsR, LinearPCA, Umap, find_col_index, PinardPlsr, Nmf, AP
from Class_Mod import LWPLSR, list_files, metrics, TpeIpls, reg_plot, resid_plot, Sk_Kmeans, DxRead, Hdbscan, read_dx, PlsProcess
from Class_Mod.DATA_HANDLING import *
from Class_Mod.Miscellaneous import prediction, download_results, plot_spectra, local_css
......
......@@ -19,7 +19,7 @@ from umap.umap_ import UMAP
from sklearn.decomposition import PCA, NMF
# Clustering
from sklearn.cluster import KMeans, HDBSCAN
from sklearn.cluster import KMeans, HDBSCAN,AffinityPropagation
from scipy.spatial.distance import euclidean, cdist
from scipy.sparse.csgraph import minimum_spanning_tree
from scipy.sparse import csgraph
......@@ -36,7 +36,6 @@ from sklearn.pipeline import Pipeline, FeatureUnion
from sklearn.compose import TransformedTargetRegressor
from sklearn.metrics import mean_absolute_error, mean_squared_error, mean_absolute_percentage_error, r2_score
from sklearn.cross_decomposition import PLSRegression
## Images and plots
from PIL import Image
import plotly.express as px
......
......@@ -157,6 +157,11 @@ if not t.empty:
non_clustered = np.where(labels == -1)
labels[non_clustered] = 1000
labels = labels.tolist()
elif clus_method == cluster_methods[3]:
cl_model = AP(X=tcr)
data, labels, clu_centers = cl_model.fit_optimal_
###### 3- Samples selection using the reduced data preentation ######
selec_strategy = ['center','random']
......
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