Giter Site home page Giter Site logo

calledit / prince Goto Github PK

View Code? Open in Web Editor NEW

This project forked from maxhalford/prince

0.0 1.0 0.0 5.85 MB

:crown: Python factor analysis library (PCA, CA, MCA, FAMD)

Home Page: http://prince.readthedocs.io/en/latest/

License: MIT License

Python 100.00%

prince's Introduction

prince_logo



Prince is an easy-to-use factor analysis library

Quick start

Prince uses pandas to manipulate dataframes, as such it expects an initial dataframe to work with. In the following example, a Principal Component Analysis (PCA) is applied to the iris dataset. Under the hood Prince decomposes the dataframe into two eigenvector matrices and one eigenvalue array thanks to a Singular Value Decomposition (SVD). The eigenvectors can then be used to project the initial dataset onto lower dimensions.

import matplotlib.pyplot as plt
import pandas as pd

import prince


df = pd.read_csv('data/iris.csv')

pca = prince.PCA(df, n_components=4)

fig1, ax1 = pca.plot_cumulative_inertia()
fig2, ax2 = pca.plot_rows(color_by='class', ellipse_fill=True)

plt.show()

The first plot displays the rows in the initial dataset projected on to the two first right eigenvectors (the obtained projections are called principal coordinates). The ellipses are 90% confidence intervals.

pca_row_principal_coordinates

The second plot displays the cumulative contributions of each eigenvector (by looking at the corresponding eigenvalues). In this case the total contribution is above 95% while only considering the two first eigenvectors.

pca_cumulative_inertia

Installation

Prince is only compatible with Python 3. Although it isn't a requirement, using Anaconda is recommended as it is generally a good idea for doing data science in Python.

Via PyPI

>>> pip install prince

Via GitHub for the latest development version

>>> pip install git+https://github.com/MaxHalford/Prince

Prince has the following dependencies:

Documentation

Please check out the documentation for a list of available methods and properties.

Example usage

You can examples in the examples/ folder, you have to navigate to the folder to use them.

>>> cd examples/
>>> python pca-iris.py

License

The MIT License (MIT). Please see the license file for more information.

prince's People

Contributors

blu3r4y avatar maxhalford avatar regonn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.