Skip to content

Commit

Permalink
add 2d example
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmad88me committed May 25, 2018
1 parent 9de63d1 commit 3a0ab0c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
2 changes: 2 additions & 0 deletions examples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import sys
sys.path.append('..')
27 changes: 27 additions & 0 deletions examples/fcm_2d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import numpy as np
import logging

import sys
sys.path.append('..')


from fuzzycmeans import FCM
from fuzzycmeans.visualization import draw_model_2d


def example():
X = np.array([[1, 1], [1, 2], [2, 2], [9, 10], [10, 10], [10, 9], [9, 9], [20,20]])
fcm = FCM(n_clusters=3)
fcm.set_logger(tostdout=True, level=logging.DEBUG)
fcm.fit(X, [0, 0, 0, 1, 1, 1, 1, 2])
# fcm.fit(X)
testing_data = np.array([[0, 1.9], [5, 3], [4, 4], [8, 9], [9.5, 6.5], [5, 5], [15,15], [12,12], [14,14], [19,10]])
predicted_membership = fcm.predict(testing_data)
print "\n\ntesting data"
print testing_data
print "predicted membership"
print predicted_membership
print "\n\n"
draw_model_2d(fcm, data=testing_data, membership=predicted_membership)

# example()
14 changes: 0 additions & 14 deletions fuzzycmeans/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,3 @@ def draw_points_2d(points, fig=None, title="figure 123", **kwargs):
output_file("output.html", title=title + " of outputfile")
return fig


# X = np.array([[1, 1], [1, 2], [2, 2], [9, 10], [10, 10], [10, 9], [9, 9]])
# fcm = FCM()
# fcm.set_logger(tostdout=True, level=logging.DEBUG)
# # fcm.fit(X, [0, 0, 0, 1, 1, 1, 1])
# fcm.fit(X)
# testing_data = np.array([[0, 1.9], [3, 3], [4, 4], [8, 9], [9.5, 6.5], [5, 5], [4.5, 4.5], [4.2, 4.2]])
# predicted_membership = fcm.predict(testing_data)
# print "\n\ntesting data"
# print testing_data
# print "predicted membership"
# print predicted_membership
# print "\n\n"
# draw_model_2d(fcm, data=testing_data, membership=predicted_membership)

0 comments on commit 3a0ab0c

Please sign in to comment.