Dữ liệu phi cấu trúc

Thiết kế quy trình Machine Learning bằng Python

Dr. Chris Anagnostopoulos

Honorary Associate Professor

Có cấu trúc và phi cấu trúc

  Class   AGE  SEX  STEROID    ...        
0    2.0  50.0  2.0      1.0    ...      
1    2.0  40.0  1.0      1.0    ...       
...
           label                                           sequence
0          VIRUS  AVTVVPDPTCCGTLSFKVPKDAKKGKHLGTFDIRQAIMDYGGLHSQ...
1  IMMUNE SYSTEM  QVQLQQPGAELVKPGASVKLSCKASGYTFTSYWMHWVKQRPGRGLE...
2  IMMUNE SYSTEM  QAVVTQESALTTSPGETVTLTCRSSTGAVTTSNYANWVQEKPDHLF...
3          VIRUS  MSQVTEQSVRFQTALASIKLIQASAVLDLTEDDFDFLTSNKVWIAT...
...

Chúng ta có thể xây dựng bộ dò gắn cờ virus là bất thường trong dữ liệu này không?

Thiết kế quy trình Machine Learning bằng Python
import stringdist
stringdist.levenshtein('abc', 'acc')
1
stringdist.levenshtein('acc', 'cce')
2
             label   sequence
169  IMMUNE SYSTEM  ILSALVGIV
170  IMMUNE SYSTEM  ILSALVGIL
stringdist.levenshtein('ILSALVGIV', 'ILSALVGIL')
1
Thiết kế quy trình Machine Learning bằng Python

Gỡ lỗi

# This won't work
pdist(proteins['sequence'].iloc[:3], metric=stringdist.levenshtein)
Traceback (most recent call last):
ValueError: A 2-dimensional array must be passed.
Thiết kế quy trình Machine Learning bằng Python

Gỡ lỗi

sequences = np.array(proteins['sequence'].iloc[:3]).reshape(-1,1)

# This won't work for a different reason pdist(sequences, metric=stringdist.levenshtein)
Traceback (most recent call last):
TypeError: argument 1 must be str, not numpy.ndarray
Thiết kế quy trình Machine Learning bằng Python

Gỡ lỗi

# This one works!!
def my_levenshtein(x, y):
    return stringdist.levenshtein(x[0], y[0])

pdist(sequences, metric=my_levenshtein)
array([136.,   2., 136.])
Thiết kế quy trình Machine Learning bằng Python

Protein ngoại lệ với ma trận tiền tính

# This takes 2 minutes for about 1000 examples
M = pdist(sequences, my_levenshtein)

Bộ dò LoF với ma trận khoảng cách đã tính sẵn:

# This takes 3 seconds
detector = lof(metric='precomputed', contamination=0.1)
preds = detector.fit_predict(M)
roc_auc_score(proteins['label'] == 'VIRUS', preds == -1)
0.64
Thiết kế quy trình Machine Learning bằng Python

Chọn khoảng cách của bạn

Thiết kế quy trình Machine Learning bằng Python

Preparing Video For Download...