Scraping Nonograms to Build a Solver Using Machine Learning

Posted on Aug 12, 2018

What and Why?

Nonograms are logic puzzles that create an image when solved and they are build from machine learning. Originally invented in the 1980's by two different people simultaneously. They became popular in the late 80s-90s. Now they're known by almost 30 different names; the most popular ones being nonograms, hanjie puzzles, picross puzzles, and griddlers. The clues on the side and top denote which squares should be empty or filled in. The numbers denote the black squares and each group of black squares must be separated by at least one empty space. Here's a really simple puzzle being solved step-by-step.

Each move has a reason and nothing is a guess. My dad, after ordering a book of puzzles, thought they might be a good machine learning project. So this web scraping project is the first step of building a nonogram solver using machine learning.

Scraping code

From this website: http://www.nonograms.org/nonograms I scraped around 8K puzzles for the size, clues, solutions, and difficulty of the puzzles. The biggest issue I came across was scraping the actual clues themselves. The actual table was hidden behind the javascript and I couldn't scrape it like everything else in the html. My solution to this was using scrapy splash in my spider as a work around as was able to get the clues as a list of empty spaces and numbers. Here is the data and its corresponding puzzle.

sizeCol 14
sizeRow 16
title Snail
number 15868
solution http://static.nonograms.org/files/nonograms/large/ulitka40_12_1_1p.png
difficulty 5
colClues  , , ,1,1, , , ,1,1, , , , ,3, , , , ,4, , , , ,4, , , ,2,6, , ,2,2,2, , ,4,2,2, ,3,1,2,1,1,2,2,1,1, ,1,1,2,1, , ,2,4,1, , ,2,1,2, , , ,7,4
rowClues  , , , , , , , ,1, , , , , , , , , , , , , , ,1,1,1, , , , , , , , , , ,1,2,2,2,1,2,1, ,2, , , ,1, , ,8,3,2,1,1,1,2,3,2,1,4, , ,2,4,10,2,2,1,1,1,1,1,1,1,1,2,2,1
size  224

For my code and data, visit my GitHub Page:  https://github.com/susarip/test/tree/master/hanjie_scraper/hanjie_scraper

What's next?

  1. Convert output images (solutions) into data which becomes the Y value
  2. Split input data set into training set and test set (90:10)
  3. Use the training set to train a few statistical machine learning algorithms
  4. Use the test set to test the trained model
  5. If the accuracy is good enough, use the model to predict answers for new puzzles.
  6. Areas of research: Use neural networks to find answers instead of statistical models

About Author

Leave a Comment

No comments found.

View Posts by Categories


Our Recent Popular Posts


View Posts by Tags

#python #trainwithnycdsa 2019 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay gbm Get Hired ggplot2 googleVis H20 Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI