Tensorflow中的互斥多标签,多类分类

时间:2018-06-04 23:55:44

标签: python tensorflow multilabel-classification

我听说过tf.nn.sigmoid_cross_entropy_with_logits,我担心它会给我的不仅仅是我的" N"每个功能的数量都有自己的类数。我正在处理与时间有关的数据,所以请考虑这个例子。

我们正在跟踪两个周期性的相关模式,每天一周: 鲑鱼吃多少小鱼,鲑鱼在一天内走多远?

然后我们尝试根据过去一周的历史来预测第二天的范围。这些范围预测是我们的标签"。 (如果有更好的方法对已经分箱的互斥范围进行分类,请告诉我)。我说互相排斥,因为如果鲑鱼吃了15-20分钟,它就不会吃5-10分钟。

以下是CSV文件的链接:https://drive.google.com/open?id=1Z7GB2c_1nF0RO2V40wWEMRvDlWIcf3Lo

如果您在Excel中打开它,请不要保存更改,因为它会解释范围" 10-15"作为日期,10月15日。

以下是一些读取数据的代码,因此您对格式感到满意。前7列是过去一周每天吃的小鱼数。接下来的7列是过去一周每天的行程距离。然后我为每组标签创建一个指标矩阵(因为我从根本上不知道如何为这个多标签问题做更复杂的事情,请指教。)

import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
import pandas as pd
from sklearn.preprocessing import label_binarize
from sklearn.utils import shuffle
from sklearn.model_selection import train_test_split
import os 
path = os.getcwd()
filepath = path + "\\Salmon.csv"
number_of_labels=2
time_periods=7

def read_data(file):
    df = pd.read_csv(file, header=None, skiprows=2)
    X = df[df.columns[0:((time_periods*number_of_labels))]].values
    y1 = df[df.columns[((time_periods*number_of_labels))]].values
    y2 = df[df.columns[((time_periods*number_of_labels)+1)]].values
    z1= np.genfromtxt(file, dtype=str, delimiter=',',skip_header=0, max_rows=1)
    y1 = label_binarize(y1, classes=z1)
    z2= np.genfromtxt(file, dtype=str, delimiter=',',skip_header=1, max_rows=1)
    y2 = label_binarize(y2, classes=z2) 
    X= X.astype(float)
    Y1= y1.astype(float)
    Y2= y2.astype(float)
    return (X, Y1, Y2, z1, z2)

X, Y1, Y2, number_of_minnows, distance_traveled = read_data(filepath)
print("X: ",X)
print("Y1: ",Y1)
print("Y2: ",Y2)
print("Number of minnows eaten ranges: ",number_of_minnows)
print("Distance traveled ranges: ",distance_traveled)

结束目标:我想养活我的" X"对所吃的小鱼和长途旅行进行检查和预测。我希望这有点灵活,以便我可以添加其他功能来跟踪。

0 个答案:

没有答案
相关问题