|
1 | | -# py-fcm |
2 | | -Fuzzy cognitive maps python library |
| 1 | +# PyFCM |
| 2 | +Fuzzy cognitive maps python library. Also, supports the topology generation from data to solve classification problems. |
| 3 | +The details associated to the generation process are described in [this paper](https://link.springer.com/chapter/10.1007/978-3-030-89691-1_25). |
| 4 | +### Installation |
3 | 5 |
|
4 | | -###Example usage |
| 6 | +#### From source: |
5 | 7 |
|
| 8 | +1. Clone repository: |
| 9 | + ``` |
| 10 | + $ git clone https://github.com/J41R0/PyFCM.git |
| 11 | + $ cd PyFCM |
| 12 | + ``` |
| 13 | +2. Install setup tools and package: |
| 14 | + ``` |
| 15 | + $ pip install setuptools |
| 16 | + $ python setup.py install |
| 17 | + ``` |
| 18 | +#### From PyPi: |
| 19 | +1. Install package using pip: |
| 20 | + ``` |
| 21 | + $ pip install py-fcm |
| 22 | + ``` |
| 23 | + |
| 24 | +### Example usage |
| 25 | +
|
| 26 | +#### Inference: |
6 | 27 | ``` |
7 | 28 | from py_fcm import from_json |
8 | 29 |
|
9 | 30 | fcm_json = """{ |
10 | | - "max_iter": 500, |
| 31 | + "max_iter": 500, |
11 | 32 | "decision_function": "LAST", |
12 | 33 | "activation_function": "sigmoid", |
13 | 34 | "memory_influence": False, |
@@ -54,6 +75,29 @@ fcm_json = """{ |
54 | 75 | """ |
55 | 76 | my_fcm = from_json(fcm_json) |
56 | 77 | my_fcm.run_inference() |
57 | | -result = my_fcm.get_result_by_type(node_type='any') |
| 78 | +result = my_fcm.get_final_state(concept_type='any') |
58 | 79 | print(result) |
| 80 | +``` |
| 81 | +
|
| 82 | +#### Generation: |
| 83 | +``` |
| 84 | +import pandas |
| 85 | +from py_fcm import FcmEstimator |
| 86 | + |
| 87 | +data_dict = { |
| 88 | + 'F1': ['x', 'x', 'y', 'y'], |
| 89 | + 'F2': [9.8, 7.3, 1.1, 3.6], |
| 90 | + 'class': ['a', 'a', 'r', 'r'] |
| 91 | +} |
| 92 | + |
| 93 | + train = pandas.DataFrame(data_dict) |
| 94 | + x_train = train.loc[:, train.columns != 'class'] |
| 95 | + y_train = train.loc[:, 'class'] |
| 96 | + |
| 97 | + estimator = FcmEstimator() |
| 98 | + estimator.fit(x_train, y_train) |
| 99 | + print(estimator.predict(x_train)) |
| 100 | + print("Accuracy: ",estimator.score(x_train, y_train)) |
| 101 | + print(estimator.get_fcm().to_json()) |
| 102 | + |
59 | 103 | ``` |
0 commit comments