What is the best way to represent or shape data with >700 features for classification?

I have a train data file that contains 0 or 1 class labels with a string containing numbers. The string is the molecular structure of the drug with a class label.

The file looks like this:

0   1730 2281 2572 2602 2611 2824 2855 2940 3149 3313 3560 3568 3824 4185 4266 4366 4409 4472 5008 5114 5408 5470 5509 5526 5626 5728 5910 5976 6031 6047 6069 6307 6352 6396 6401 6439 6468 6477 6708 6978 7092 7112 7149 7235 7470 7495 7549 7714 7815 7911 8037 8464 8488 8601 8650 8797 8825 8830 9015 9275 9447 9577 9707 9735 10200 10234 10328 10469 10471 10637 10749 10938 11042 11378 11713 11728 11756 11858 11950 12142 12160 12375 12383 12540 12906 13002 13121 13401 13700 14147 14332 14565 14581 14707 14944 15213 15423 15608 15677 15859 16028 16043 16092 16145 16323 16419 16564 17009 17161 17252 17361 17515 17698 17760 17791 17957 18135 18722 18889 18914 19030 19082 19105 19166 19199 19532 19716 19857 19958 20146 20153 20154 20354 20503 20582 20587 21109 21484 21543 21690 21904 21967 22009 22105 22154 22757 22808 22813 23066 23176 23361 23505 23602 23650 23868 24410 24718 24820 24869 24967 25051 25136 25174 25299 25340 25419 25568 25578 25608 25803 25930 26245 26465 26729 26795 26807 27211 27340 27750 27810 28017 28020 28070 28192 28250 28606 28671 28811 28880 29029 29061 29071 29103 29298 29350 29372 29384 29419 29432 29752 29961 30039 30237 30245 30314 30326 30433 30463 30552 30582 30748 30784 30840 30945 30965 31025 31192 30786 40822 40882 41407 41410 41457 41540 41996 42011 42265 42299 42425 42209 50240 50322 50399 50506 50601 50710 50876 50923 51028 51066 51434 51724 51846 51951 52291 52321 52425 52659 52686 53022 53255 53266 53315 53338 53455 53760 53948 53976 54059 54103 54131 54136 54151 54161 54244 54452 54526 54746 55113 55283 55367 55424 55650 55972 56061 56114 56211 56410 56681 56725 56887 57155 57173 57180 57313 57474 57481 57506 57612 57762 57765 58149 58401 58459 58716 58832 58867 59013 59117 59340 59522 59744 59922 60085 60205 60272 60280 60489 60546 60572 60587 60778 60853 60962 61142 61214 61405 61504 61576 61607 61771 62139 62214 62419 62483 62520 62773 62905 62940 63150 63200 63466 63479 63508 63513 63685 63830 64247 64313 64356 64436 64450 64459 64461 64521 64904 65048 65142 65217 65241 65318 65518 65555 65651 65713 65750 65804 65911 66071 66081 66157 66182 66364 66531 66541 66691 66872 67050 67105 67214 67475 67582 67637 67810 67957 67986 68103 68279 68353 68500 68574 68601 68623 68796 68798 68948 69517 69646 69734 69773 69956 70071 70486 71106 71114 71425 72008 72253 72289 72311 72377 72456 72498 72601 72650 72730 72733 72822 72826 73170 73235 73315 73322 73330 73335 73473 73595 73673 73686 73821 73916 74108 74316 74773 74808 74865 75036 75220 75247 75393 75396 75399 75645 75676 75790 75823 76023 76090 76172 76370 76581 76881 76886 77050 77202 77523 77578 77648 77870 78150 78222 78353 78375 78583 78655 78802 789 90725 90880 90909 90954 91307 91315 91408 91828 91923 91927 91931 91996 92109 92204 92221 92278 92560 92704 92839 92929 92931 92966 92983 92988 93016 93136 93307 93539 93622 93735 93972 94210 94211 94226 94493 94583 94611 94618 94715 95145 95170 95347 95360 95371 95546 95566 95629 95646 95685 95876 95986 96422 96502 96567 96685 96769 96844 96998 97062 97204 97947 97977 98061 98190 98214 98231 98277 98402 98543 98581 98654 98831 98959 99116 99187 99257 99321 99349 99580 99678 99686 99998 
0   118 307 367 478 505 512 807 878 939 1024 1095 1836 1915 1961 2261 2474 2521 2633 2673 2969 3143 3193 3292 3313 3593 3906 4073 4104 4605 4684 4720 5168 5264 5422 5456 5470 5537 5629 5895 5932 6052 6305 6319 6330 6601 6671 6891 6946 7065 7142 7260 7446 7517 7582 7609 7947 7965 7993 8015 8098 8367 8410 8490 8532 8549 8700 8837 9043 9086 9146 9247 9427 9735 10090 10141 10229 10235 10489 10614 10833 10955 11172 11238 11807 11820 11858 11989 12092 12216 12262 12533 12534 12923 13159 13306 13621 13677 13685 13824 14052 14053 14176 14179 14203 14222 14481 14600 14654 14732 14763 14782 14859 15105 15348 15956 16041 16073 16320 16490 16528 16558 16746 16835 16 74524 74560 74651 74765 74947 75069 75220 75504 75939 76317 76484 76571 76803 76826 77013 77256 77453 77546 77649 77789 77870 77891 77945 77981 78001 78157 78840 78998 79482 79864 79869 79920 80092 80104 80113 80200 80256 80376 80543 80592 80767 80897 81142 81261 81281 81381 81566 81690 82258 82517 82533 82538 82641 82684 82839 82871 83189 83427 83435 83620 83821 83914 84352 84516 84528 84530 84574 84879 85158 85378 85390 85517 85867 86106 86197 86207 86271 86306 86516 86818 87149 87207 87293 87385 87496 87662 87686 87744 87769 87775 87927 87939 88153 88174 88745 88767 88901 88946 88957 88990 88993 89106 89130 89283 89652 89872 90028 90123 90138 90220 90237 90349 90441 90446 90487 90818 91086 91160 91188 91237 91353 91593 91684 91737 91810 91943 92204 92346 92350 92381 92515 92779 92814 93085 93226 93357 93440 93531 94009 94026 94120 94173 94240 94518 94696 94757 94770 94852 94931 94979 95021 95130 95371 95758 95877 96172 96268 96271 96409 96427 96441 96480 96536 96593 96741 96815 96852 96886 96959 97018 97215 97385 97398 97848 97877 97889 98260 98268 98452 98676 98756 98801 98808 98928 99025 99104 99220 99606 99628 99801 
0   87 149 433 704 711 892 988 1056 1070 1234 1246 1289 1642 1669 1861 1924 1956 2081 2150 2909 3038 3070 3082 3589 3708 3709 3713 4011 4266 4404 4489 4534 4674 4688 5114 5133 5190 5253 5815 6114 6645 6750 6767 6862 6880 6960 6986 7028 7080 7112 7262 7426 7492 7494 7522 7614 8100 8258 8581 8631 8799 8824 8872 8958 9011 9146 9197 9202 9247 9249 9300 9324 9353 9391 9392 9669 10234 10314 10323 10341 10455 10471 10764 10811 10871 10938 10973 11210 11277 11317 11331 11470 11581 11588 11670 11820 12199 12250 12274 12372 12425 12471 12504 12505 12540 12575 12764 12801 13424 13457 13561 13587 13650 13700 13832 13873 13916 13974 14044 14203 14246 14386 14454 14676 14942 14952 15372 15555 15570 15938 16176 16233 16268 16274 16419 16765 16820 17236 17260 17287 17307 17319 17324 17369 17674 17714 17749 18091 18154 18327 18630 18957 19072 19395 19943 19962 20179 20355 20728 20807 20850 20958 21068 21424 21890 22029 22165 22314 22316 22548 22620 22764 22820 23018 23197 23326 23671 23707 24003 24178 24205 24258 24324 24347 24401 24405 24569 24820 24939 25172 25352 25541 25783 25952 26022 26376 26523 267295 36435 36605 36732 36931 37155 37242 37263 37347 37420 37431 37496 37589 37627 37824 38249 38385 38481 38551 38715 38752 38915 39157 45730 45770 45881 4595

Each string has a different number of segments (sequence of numbers). I need to do some feature reduction on this training set possibly using RandomForests or another approach. I'm unclear on how I should represent this data so that I can work on it and pass it to a model in scikit-learn. I tried putting it into a dataframe in Python but then that leads to a "jagged" dataframe which is hard to work with. I also need to calculate Variance Threshold.

Any suggestions on how to use this file?

Answers


You need to vectorize your data so that you have a square matrix with one column for each possible value. You can do this using a CountVectorizer (this is usually used for processing text but it will work for your data as well). The output will be a sparse matrix, depending on the model that you want to use, you may have to convert this to a dense array using np.array

from sklearn.feature_extraction.text import CountVectorizer
vec = CountVectorizer(binary=True, vocabulary=[str(i) for i in range(100000)])
X = vec.fit_transform(df[1])
X
# <162x56905 sparse matrix of type '<class 'numpy.int64'>'
#   with 147915 stored elements in Compressed Sparse Row format>
X.toarray()
# array([[0, 0, 0, ..., 0, 1, 0],
#        [0, 0, 0, ..., 0, 0, 0],
#        [0, 0, 0, ..., 0, 0, 0],
#        ...,
#        [0, 0, 0, ..., 0, 0, 0],
#        [0, 0, 0, ..., 0, 0, 0],
#        [0, 0, 0, ..., 0, 0, 0]])

Need Your Help

SQL Server join to same table multiple times with the on clause having an and

sql sql-server inner-join

I am trying to take multiple rows of data and combine them into one row. The input data looks like this:

Libgdx Screen Confusion

java android libgdx

Hello this is my first time posting on here and am relatively new to coding. I've been playing around with java and libgdx for a month or two and I'm confused about one thing for screens.