Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from scikits.learn.lda import LDA
- str_data = """\
- affected proband sex a b c d e f
- F F M 0.450 0.410 0.420 0.400 0.440 0.510
- F F F 0.610 0.520 0.480 0.690 0.530 0.430
- T T F 0.570 0.430 0.320 0.620 0.420 0.480
- T F F 0.660 0.390 0.620 0.550 0.650 0.530
- T T M 0.550 0.490 0.640 0.630 0.640 0.670
- T F F 0.650 0.570 0.450 0.610 0.480 0.610
- T T M 0.550 0.560 0.490 0.540 0.510 0.570
- F F F 0.590 0.560 0.790 0.740 0.730 0.660
- F F M 0.700 0.580 0.610 0.820 0.720 0.690"""
- all_data = [x.split() for x in str_data.split("\n")]
- X = np.array([map(float, row[3:]) for row in all_data[1:]])
- labels = ["/".join(row[:3]) for row in all_data[1:]]
- y_lookup = dict((l, i) for i, l in enumerate(set(labels)))
- y = np.array([y_lookup[l] for l in labels])
- lda = LDA(n_components=2)
- lda.fit(X, y)
- # predict ok
- y_predict = lda.predict(X)
- print sum(y_predict == y) / float(y.size)
- # transform has bad dimensions (not aligned for np.dot)
- # but works with n_components=None
- X_r = lda.transform(X)
Add Comment
Please, Sign In to add comment