ml-finance-python

python scripts for finance machine learning

git clone https://9o.is/git/ml-finance-python.git

gaussian_mixture_model.py

(565B)


      1 from __future__ import division, print_function
      2 import sys
      3 import os
      4 import math
      5 import random
      6 from sklearn import datasets
      7 import numpy as np
      8 
      9 from mlfromscratch.unsupervised_learning import GaussianMixtureModel
     10 from mlfromscratch.utils import Plot
     11 
     12 
     13 def main():
     14     # Load the dataset
     15     X, y = datasets.make_blobs()
     16 
     17     # Cluster the data
     18     clf = GaussianMixtureModel(k=3)
     19     y_pred = clf.predict(X)
     20 
     21     p = Plot()
     22     p.plot_in_2d(X, y_pred, title="GMM Clustering")
     23     p.plot_in_2d(X, y, title="Actual Clustering")
     24 
     25 
     26 if __name__ == "__main__":
     27     main()