ml-finance-python

python scripts for finance machine learning

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

dbscan.py

(642B)


      1 import sys
      2 import os
      3 import math
      4 import random
      5 from sklearn import datasets
      6 import numpy as np
      7 
      8 # Import helper functions
      9 from mlfromscratch.utils import Plot
     10 from mlfromscratch.unsupervised_learning import DBSCAN
     11 
     12 def main():
     13     # Load the dataset
     14     X, y = datasets.make_moons(n_samples=300, noise=0.08, shuffle=False)
     15 
     16     # Cluster the data using DBSCAN
     17     clf = DBSCAN(eps=0.17, min_samples=5)
     18     y_pred = clf.predict(X)
     19 
     20     # Project the data onto the 2 primary principal components
     21     p = Plot()
     22     p.plot_in_2d(X, y_pred, title="DBSCAN")
     23     p.plot_in_2d(X, y, title="Actual Clustering")
     24 
     25 if __name__ == "__main__":
     26     main()