Last active
August 21, 2020 18:55
-
-
Save dan-r95/46f7e6e82c578cded35edadfcad6852d to your computer and use it in GitHub Desktop.
💯
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# either when comp is turning 1 or failure equals comp1 | |
# turn ob the life eihter when maintenance happened or failure! | |
labeled_features['life_comp1'] = labeled_features.groupby((labeled_features['comp1'] != labeled_features['comp1'].shift(1)).cumsum()).cumcount()+1 | |
labeled_features['life_comp2'] = labeled_features.groupby((labeled_features['comp2'] != labeled_features['comp2'].shift(1)).cumsum()).cumcount()+1 | |
labeled_features['life_comp3'] = labeled_features.groupby((labeled_features['comp3'] != labeled_features['comp3'].shift(1)).cumsum()).cumcount()+1 | |
labeled_features['life_comp4'] = labeled_features.groupby((labeled_features['comp4'] != labeled_features['comp4'].shift(1)).cumsum()).cumcount()+1 | |
#print(labeled_features.groupby((labeled_features['comp1'] != labeled_features['comp1'].shift(1)).cumsum()).tail(1)) | |
#print(labeled_features.groupby((labeled_features['comp1'] != labeled_features['comp1'].shift(1)).cumsum())) | |
#print(labeled_features.groupby((labeled_features['comp1'] != labeled_features['comp1'].shift(1)).cumsum()).nlargest(1)) | |
#print(labeled_features.groupby((labeled_features['comp1'] != labeled_features['comp1'].shift(1)).cumsum()).describe()) | |
groups =labeled_features.groupby((labeled_features['comp1'] != labeled_features['comp1'].shift(1)).cumsum()) #.first()) | |
#print(groups.get_group(3)) | |
# for each in groups | |
# for the first group ... apply to the next group | |
print(len(groups)) | |
print("########") | |
rowWithLastStepAndErrorStep= groups.tail(1) | |
print(rowWithLastStepAndErrorStep.shape) | |
print(rowWithLastStepAndErrorStep.head(10)[["comp1","life_comp1", "failure"]]) | |
#get every second row | |
print("###### each second") | |
maxLifeInThatCycle = rowWithLastStepAndErrorStep.iloc[::2, :].head(10)[["comp1","life_comp1", "failure"]] | |
print("#### all acutals errorz") | |
actualErrors = rowWithLastStepAndErrorStep.iloc[1::2, :].head(10)[["comp1","life_comp1", "failure"]] | |
maxLifeInThatCycle | |
rowWithLastStepAndErrorStep["T"] = 0 | |
# because a failure happened, the machine crashed, ergo T = 1 | |
#rowWithLastStepAndErrorStep["T"] = | |
print("############ Sangria") | |
#print(rowWithLastStepAndErrorStep.loc[rowWithLastStepAndErrorStep.shift(1)["failure"] == "comp1"][["comp1","life_comp1", "failure"]].head(10)) | |
rowWithLastStepAndErrorStep.loc[rowWithLastStepAndErrorStep.shift(1)["failure"] == "comp1"]#["T"] = 1 | |
print(rowWithLastStepAndErrorStep[["comp1","life_comp1", "failure", "T"]].head(40)) | |
print(rowWithLastStepAndErrorStep.shape) | |
#print(rowWithLastStepAndErrorStep) | |
print(rowWithLastStepAndErrorStep.loc[rowWithLastStepAndErrorStep.shift(1).loc[:, "failure"] == "comp1"].shape) | |
fixedRows = rowWithLastStepAndErrorStep.loc[rowWithLastStepAndErrorStep.shift(1).loc[:, "failure"] == "comp1"].copy()#.loc[:,"T"] = 1 | |
#print(rowWithLastStepAndErrorStep.loc[rowWithLastStepAndErrorStep.shift(1)["failure"] == "comp1"]["T"]) | |
fixedRows["T"] = 1 | |
print(fixedRows[["machineID", "comp1","life_comp1", "failure", "T"]].head()) | |
print(rowWithLastStepAndErrorStep["T"].value_counts()) | |
rowWithLastStepAndErrorStep.update(fixedRows) | |
#only the second rows | |
print(rowWithLastStepAndErrorStep.iloc[::2, :]["T"].value_counts()) | |
print(rowWithLastStepAndErrorStep["T"].value_counts()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment