-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #313 from navinrathore/PythonPhases
Updates in Python classes and 'assessModel' python phase
- Loading branch information
Showing
11 changed files
with
305 additions
and
58 deletions.
There are no files selected for viewing
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
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
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
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
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
26 changes: 26 additions & 0 deletions
26
client/src/test/java/zingg/client/TestFieldDefinition.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package zingg.client; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestFieldDefinition { | ||
public static final Log LOG = LogFactory.getLog(TestFieldDefinition.class); | ||
|
||
@Test | ||
public void testConvertAListOFMatchTypesIntoString() { | ||
try { | ||
List<MatchType> matchType = Arrays.asList(MatchType.EMAIL, MatchType.FUZZY, MatchType.NULL_OR_BLANK); | ||
String expectedString = "EMAIL,FUZZY,NULL_OR_BLANK"; | ||
String strMatchType = FieldDefinition.MatchTypeSerializer.getStringFromMatchType(matchType); | ||
assertEquals(expectedString, strMatchType); | ||
} catch (Exception | ZinggClientException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,51 @@ | ||
from zingg import * | ||
from pyspark.sql import DataFrame | ||
import pandas as pd | ||
import seaborn as sn | ||
import matplotlib.pyplot as plt | ||
import sys | ||
from IPython.display import display | ||
|
||
args = Arguments() | ||
fname = FieldDefinition("fname","\"string\"",[sc._jvm.zingg.client.MatchType.FUZZY]) | ||
lname = FieldDefinition("lname","\"string\"",[sc._jvm.zingg.client.MatchType.FUZZY]) | ||
fieldDef = [fname, lname] | ||
options = sc._jvm.zingg.client.ClientOptions(["--phase", "label", "--conf", "dummy", "--license", "dummy", "--email", "[email protected]"]) | ||
inputPipe = Pipe("test", "csv") | ||
inputPipe.addProperty("location", "examples/febrl/test.csv") | ||
args.setData(inputPipe) | ||
args.setModelId("100") | ||
args.setZinggDir("models") | ||
args.setNumPartitions(4) | ||
args.setLabelDataSampleSize(0.5) | ||
args.setFieldDefinition(fieldDef) | ||
print(args.getArgs) | ||
#Zingg execution for the given phase | ||
client = Client(args, options) | ||
client.init() | ||
client.execute() | ||
jMarkedDF = client.getMarkedRecords() | ||
print(jMarkedDF) | ||
markedDF = DataFrame(jMarkedDF, sqlContext) | ||
print(markedDF) | ||
pMarkedDF = markedDF.toPandas() | ||
display(pMarkedDF) | ||
|
||
#marked = client.getMarkedRecordsStat(mark, value) | ||
#matched_marked = client.getMatchedMarkedRecordsStat(mark) | ||
#unmatched_marked = client.getUnmatchedMarkedRecordsStat(mark) | ||
#unsure_marked = client.getUnsureMarkedRecordsStat(mark) | ||
logging.basicConfig(level=logging.INFO) | ||
LOG = logging.getLogger("zingg.assessModel") | ||
|
||
def main(): | ||
LOG.info("Phase AssessModel starts") | ||
|
||
#excluding argv[0] that is nothing but the current executable file | ||
options = ClientOptions(sys.argv[1:]) | ||
options.setPhase("label") | ||
arguments = Arguments.createArgumentsFromJSON(options.getConf(), options.getPhase()) | ||
client = Zingg(arguments, options) | ||
client.init() | ||
|
||
pMarkedDF = client.getPandasDfFromDs(client.getMarkedRecords()) | ||
pUnMarkedDF = client.getPandasDfFromDs(client.getUnMarkedRecords()) | ||
|
||
total_marked = pMarkedDF.shape[0] | ||
total_unmarked = pUnMarkedDF.shape[0] | ||
matched_marked = client.getMatchedMarkedRecordsStat() | ||
unmatched_marked = client.getUnmatchedMarkedRecordsStat() | ||
unsure_marked = client.getUnsureMarkedRecordsStat() | ||
|
||
LOG.info("") | ||
LOG.info("No. of Records Marked : %d", total_marked) | ||
LOG.info("No. of Records UnMarked : %d", total_unmarked) | ||
LOG.info("No. of Matches : %d", matched_marked) | ||
LOG.info("No. of Non-Matches : %d", unmatched_marked) | ||
LOG.info("No. of Not Sure : %d", unsure_marked) | ||
LOG.info("") | ||
plotConfusionMatrix(pMarkedDF) | ||
|
||
LOG.info("Phase AssessModel ends") | ||
|
||
def plotConfusionMatrix(pMarkedDF): | ||
#As no model is yet created and Zingg is still learning, removing the records with prediciton = -1 | ||
pMarkedDF.drop(pMarkedDF[pMarkedDF[ColName.PREDICTION_COL] == -1].index, inplace=True) | ||
|
||
confusion_matrix = pd.crosstab(pMarkedDF[ColName.MATCH_FLAG_COL], pMarkedDF[ColName.PREDICTION_COL], rownames=['Actual'], colnames=['Predicted']) | ||
confusion_matrix = confusion_matrix / 2 | ||
sn.heatmap(confusion_matrix, annot=True) | ||
plt.show() | ||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.