diff --git a/examples/__init__.py b/examples/__init__.py new file mode 100644 index 0000000..f974bf6 --- /dev/null +++ b/examples/__init__.py @@ -0,0 +1,2 @@ +import sys +sys.path.append('..') diff --git a/examples/fcm_2d.py b/examples/fcm_2d.py new file mode 100644 index 0000000..54030ca --- /dev/null +++ b/examples/fcm_2d.py @@ -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() diff --git a/fuzzycmeans/visualization.py b/fuzzycmeans/visualization.py index 384f2f1..9d463b2 100644 --- a/fuzzycmeans/visualization.py +++ b/fuzzycmeans/visualization.py @@ -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)