I'm trying to cluster tractor sensor data by row in a python script. For the moment I'm trying to find data orientation after a FastICA (sklearn), vertical or horizontal. Because for same data, FastICA can orientate results differently.

Same data, different orientation

Until now, I was searching for an empirical rule with the 2 matrix FastICA().components_ and FastICA().mixing_. But I found nothing that works.

Is somebody have an better idea?

Here is data and my code below:

import geopandas as gpd
import numpy as np

shp_name = 'rawdata379'

shp_source = ('/home/jovyan/scripts/physiocap/Test_Data/{}.shp'.format(shp_name))
source = gpd.read_file(shp_source)
source = source.to_crs({'init' :'epsg:3857'})

src_coord = source[['LONGITUDE', 'LATITUDE']]

from sklearn.decomposition import FastICA
import pandas as pd
from shapely.geometry import Point

rng = np.random.RandomState(42)

pca = FastICA(n_components=2, algorithm='parallel', whiten=True, max_iter=100)
src_coord_pca = pca.fit_transform(src_coord)

src_coord_pca_df = pd.DataFrame(src_coord_pca).rename(columns={0:'X', 1:'Y'})
src_coord_pca_df['geometry'] = list(zip(src_coord_pca_df['X'], src_coord_pca_df['Y']))
src_coord_pca_df['geometry'] = src_coord_pca_df['geometry'].apply(Point)
src_coord_pca_gdf = gpd.GeoDataFrame(src_coord_pca_df, geometry='geometry')
src_coord_pca_gdf.plot(figsize=(9, 9))

compo, feat = pca.components_
print('compo :', compo)
print('feat :', feat)

feat, compo = pca.mixing_
print('compo :', compo)
print('feat :', feat)

#trial of empirical rule
if (pca.components_[0][0] > 0 != pca.components_[0][1] > 0):
    src_coord_pca_df = pd.DataFrame(src_coord_pca)[0]

    src_coord_pca_df = pd.DataFrame(src_coord_pca)[1]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.